blob: d7676ed68a30a180e3fd9c09fdc4ec023eb0ffa1 [file] [log] [blame]
[email protected]00c39612010-03-06 02:53:281// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/renderer/render_widget.h"
6
[email protected]6c077af2010-03-19 14:01:337#include "app/surface/transport_dib.h"
[email protected]4fb66842009-12-04 21:41:008#include "base/command_line.h"
initial.commit09911bf2008-07-26 23:55:299#include "base/logging.h"
10#include "base/message_loop.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/scoped_ptr.h"
[email protected]661eb9d2009-02-03 02:11:4812#include "build/build_config.h"
[email protected]4fb66842009-12-04 21:41:0013#include "chrome/common/chrome_switches.h"
[email protected]674741932009-02-04 23:44:4614#include "chrome/common/render_messages.h"
[email protected]8085dbc82008-09-26 22:53:4415#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2816#include "chrome/renderer/render_thread.h"
[email protected]e0fc2f12010-03-14 23:30:5917#include "gfx/point.h"
18#include "gfx/size.h"
[email protected]661eb9d2009-02-03 02:11:4819#include "skia/ext/platform_canvas.h"
[email protected]d5282e72009-05-13 13:16:5220#include "third_party/skia/include/core/SkShader.h"
[email protected]418ed5ab2009-11-12 01:14:4921#include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h"
22#include "third_party/WebKit/WebKit/chromium/public/WebPopupMenu.h"
23#include "third_party/WebKit/WebKit/chromium/public/WebPopupMenuInfo.h"
24#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
25#include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h"
26#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]8c89e7792009-08-19 21:18:3427#include "webkit/glue/webkit_glue.h"
[email protected]661eb9d2009-02-03 02:11:4828
29#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4930#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5231#include "third_party/skia/include/core/SkPixelRef.h"
32#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4833#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4434
[email protected]418ed5ab2009-11-12 01:14:4935#include "third_party/WebKit/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2936
[email protected]4873c7d2009-07-16 06:36:2837using WebKit::WebCompositionCommand;
[email protected]7c51b0ee2009-07-08 21:49:3038using WebKit::WebCursorInfo;
[email protected]62cb33cae2009-03-27 23:30:2239using WebKit::WebInputEvent;
[email protected]4873c7d2009-07-16 06:36:2840using WebKit::WebNavigationPolicy;
41using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5942using WebKit::WebPopupMenuInfo;
[email protected]b3f2b912009-04-09 16:18:5243using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1944using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5245using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2846using WebKit::WebTextDirection;
[email protected]62cb33cae2009-03-27 23:30:2247
[email protected]3e2b375b2010-04-07 17:03:1248RenderWidget::RenderWidget(RenderThreadBase* render_thread,
49 WebKit::WebPopupType popup_type)
initial.commit09911bf2008-07-26 23:55:2950 : routing_id_(MSG_ROUTING_NONE),
[email protected]c5b3b5e2009-02-13 06:41:1151 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2952 opener_id_(MSG_ROUTING_NONE),
[email protected]8085dbc82008-09-26 22:53:4453 render_thread_(render_thread),
[email protected]659f73f2009-10-13 13:43:4254 host_window_(0),
initial.commit09911bf2008-07-26 23:55:2955 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2956 next_paint_flags_(0),
[email protected]53d3f302009-12-21 04:42:0557 update_reply_pending_(false),
initial.commit09911bf2008-07-26 23:55:2958 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2959 is_hidden_(false),
60 needs_repainting_on_restore_(false),
61 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4962 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4863 closing_(false),
initial.commit09911bf2008-07-26 23:55:2964 ime_is_active_(false),
65 ime_control_enable_ime_(true),
66 ime_control_x_(-1),
67 ime_control_y_(-1),
68 ime_control_new_state_(false),
[email protected]0ebf3872008-11-07 21:35:0369 ime_control_updated_(false),
[email protected]9f23f592008-11-17 08:36:3470 ime_control_busy_(false),
[email protected]3e2b375b2010-04-07 17:03:1271 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:4872 pending_window_rect_count_(0),
[email protected]9d166af2010-03-02 22:04:3373 suppress_next_char_events_(false) {
[email protected]8930d472009-02-21 08:05:2874 RenderProcess::current()->AddRefProcess();
[email protected]8085dbc82008-09-26 22:53:4475 DCHECK(render_thread_);
initial.commit09911bf2008-07-26 23:55:2976}
77
78RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:1179 DCHECK(!webwidget_) << "Leaking our WebWidget!";
initial.commit09911bf2008-07-26 23:55:2980 if (current_paint_buf_) {
[email protected]8930d472009-02-21 08:05:2881 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
initial.commit09911bf2008-07-26 23:55:2982 current_paint_buf_ = NULL;
83 }
[email protected]8930d472009-02-21 08:05:2884 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:2985}
86
87/*static*/
[email protected]8085dbc82008-09-26 22:53:4488RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]0ebf3872008-11-07 21:35:0389 RenderThreadBase* render_thread,
[email protected]3e2b375b2010-04-07 17:03:1290 WebKit::WebPopupType popup_type) {
initial.commit09911bf2008-07-26 23:55:2991 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]0ebf3872008-11-07 21:35:0392 scoped_refptr<RenderWidget> widget = new RenderWidget(render_thread,
[email protected]3e2b375b2010-04-07 17:03:1293 popup_type);
initial.commit09911bf2008-07-26 23:55:2994 widget->Init(opener_id); // adds reference
95 return widget;
96}
97
[email protected]88efb7ec2009-07-14 16:32:5998void RenderWidget::ConfigureAsExternalPopupMenu(const WebPopupMenuInfo& info) {
99 popup_params_.reset(new ViewHostMsg_ShowPopup_Params);
100 popup_params_->item_height = info.itemHeight;
[email protected]c9e19792010-03-17 17:02:59101 popup_params_->item_font_size = info.itemFontSize;
[email protected]88efb7ec2009-07-14 16:32:59102 popup_params_->selected_item = info.selectedIndex;
103 for (size_t i = 0; i < info.items.size(); ++i)
104 popup_params_->popup_items.push_back(WebMenuItem(info.items[i]));
105}
106
initial.commit09911bf2008-07-26 23:55:29107void RenderWidget::Init(int32 opener_id) {
108 DCHECK(!webwidget_);
109
110 if (opener_id != MSG_ROUTING_NONE)
111 opener_id_ = opener_id;
112
[email protected]4873c7d2009-07-16 06:36:28113 webwidget_ = WebPopupMenu::create(this);
initial.commit09911bf2008-07-26 23:55:29114
[email protected]8085dbc82008-09-26 22:53:44115 bool result = render_thread_->Send(
[email protected]3e2b375b2010-04-07 17:03:12116 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
initial.commit09911bf2008-07-26 23:55:29117 if (result) {
[email protected]8085dbc82008-09-26 22:53:44118 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29119 // Take a reference on behalf of the RenderThread. This will be balanced
120 // when we receive ViewMsg_Close.
121 AddRef();
122 } else {
123 DCHECK(false);
124 }
125}
126
127// This is used to complete pending inits and non-pending inits. For non-
128// pending cases, the parent will be the same as the current parent. This
129// indicates we do not need to reparent or anything.
[email protected]18bcc3c2009-01-27 21:39:15130void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29131 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29132
133 host_window_ = parent_hwnd;
134
[email protected]6de74452009-02-25 18:04:59135 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29136}
137
138IPC_DEFINE_MESSAGE_MAP(RenderWidget)
139 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
140 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
141 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
142 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
143 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]53d3f302009-12-21 04:42:05144 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]8400e032010-02-26 18:50:11145 IPC_MESSAGE_HANDLER(ViewMsg_CreateVideo_ACK, OnCreateVideoAck)
146 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVideo_ACK, OnUpdateVideoAck)
initial.commit09911bf2008-07-26 23:55:29147 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
148 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
149 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
150 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetInputMode, OnImeSetInputMode)
151 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
[email protected]ec7dc112008-08-06 05:30:12152 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
[email protected]07f953332009-03-25 04:31:11153 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
[email protected]2533ce12009-05-09 00:02:24154 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
initial.commit09911bf2008-07-26 23:55:29155 IPC_MESSAGE_UNHANDLED_ERROR()
156IPC_END_MESSAGE_MAP()
157
158bool RenderWidget::Send(IPC::Message* message) {
159 // Don't send any messages after the browser has told us to close.
160 if (closing_) {
161 delete message;
162 return false;
163 }
164
165 // If given a messsage without a routing ID, then assign our routing ID.
166 if (message->routing_id() == MSG_ROUTING_NONE)
167 message->set_routing_id(routing_id_);
168
[email protected]d3fc25652009-02-24 22:31:25169 return render_thread_->Send(message);
[email protected]8085dbc82008-09-26 22:53:44170}
171
initial.commit09911bf2008-07-26 23:55:29172// Got a response from the browser after the renderer decided to create a new
173// view.
[email protected]18bcc3c2009-01-27 21:39:15174void RenderWidget::OnCreatingNewAck(gfx::NativeViewId parent) {
initial.commit09911bf2008-07-26 23:55:29175 DCHECK(routing_id_ != MSG_ROUTING_NONE);
176
177 CompleteInit(parent);
178}
179
180void RenderWidget::OnClose() {
181 if (closing_)
182 return;
183 closing_ = true;
184
185 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03186 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]8085dbc82008-09-26 22:53:44187 render_thread_->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03188 SetHidden(false);
189 }
initial.commit09911bf2008-07-26 23:55:29190
initial.commit09911bf2008-07-26 23:55:29191 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25192 // now. Post a task that only gets invoked when there are no nested message
193 // loops.
194 MessageLoop::current()->PostNonNestableTask(FROM_HERE,
195 NewRunnableMethod(this, &RenderWidget::Close));
196
197 // Balances the AddRef taken when we called AddRoute.
198 Release();
initial.commit09911bf2008-07-26 23:55:29199}
200
[email protected]f21c613a2009-02-12 14:46:17201void RenderWidget::OnResize(const gfx::Size& new_size,
202 const gfx::Rect& resizer_rect) {
initial.commit09911bf2008-07-26 23:55:29203 // During shutdown we can just ignore this message.
204 if (!webwidget_)
205 return;
206
[email protected]f21c613a2009-02-12 14:46:17207 // Remember the rect where the resize corner will be drawn.
208 resizer_rect_ = resizer_rect;
209
initial.commit09911bf2008-07-26 23:55:29210 // TODO(darin): We should not need to reset this here.
[email protected]bee16aab2009-08-26 15:55:03211 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29212 needs_repainting_on_restore_ = false;
213
214 // We shouldn't be asked to resize to our current size.
215 DCHECK(size_ != new_size);
216 size_ = new_size;
217
218 // We should not be sent a Resize message if we have not ACK'd the previous
219 DCHECK(!next_paint_is_resize_ack());
220
[email protected]552e6002009-11-19 05:24:57221 paint_aggregator_.ClearPendingUpdate();
222
initial.commit09911bf2008-07-26 23:55:29223 // When resizing, we want to wait to paint before ACK'ing the resize. This
224 // ensures that we only resize as fast as we can paint. We only need to send
225 // an ACK if we are resized to a non-empty rect.
[email protected]4873c7d2009-07-16 06:36:28226 webwidget_->resize(new_size);
initial.commit09911bf2008-07-26 23:55:29227 if (!new_size.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57228 // Resize should have caused an invalidation of the entire view.
229 DCHECK(paint_aggregator_.HasPendingUpdate());
[email protected]2d5d09d52009-06-15 14:29:21230
initial.commit09911bf2008-07-26 23:55:29231 // We will send the Resize_ACK flag once we paint again.
232 set_next_paint_is_resize_ack();
233 }
234}
235
236void RenderWidget::OnWasHidden() {
237 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03238 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29239}
240
241void RenderWidget::OnWasRestored(bool needs_repainting) {
242 // During shutdown we can just ignore this message.
243 if (!webwidget_)
244 return;
245
246 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03247 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29248
249 if (!needs_repainting && !needs_repainting_on_restore_)
250 return;
251 needs_repainting_on_restore_ = false;
252
[email protected]4fb66842009-12-04 21:41:00253 // Tag the next paint as a restore ack, which is picked up by DoDeferredUpdate
initial.commit09911bf2008-07-26 23:55:29254 // when it sends out the next PaintRect message.
255 set_next_paint_is_restore_ack();
256
257 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:28258 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
initial.commit09911bf2008-07-26 23:55:29259}
260
[email protected]53d3f302009-12-21 04:42:05261void RenderWidget::OnRequestMoveAck() {
262 DCHECK(pending_window_rect_count_);
263 pending_window_rect_count_--;
264}
265
266void RenderWidget::OnUpdateRectAck() {
267 DCHECK(update_reply_pending());
268 update_reply_pending_ = false;
269
270 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
271 // have no current update buf.
[email protected]b7fce1f2008-08-14 05:01:07272 if (current_paint_buf_) {
[email protected]8930d472009-02-21 08:05:28273 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
[email protected]b7fce1f2008-08-14 05:01:07274 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29275 }
[email protected]e68e62fa2009-02-20 02:00:04276
[email protected]00c39612010-03-06 02:53:28277 // Notify subclasses.
278 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25279
initial.commit09911bf2008-07-26 23:55:29280 // Continue painting if necessary...
[email protected]552e6002009-11-19 05:24:57281 CallDoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29282}
283
[email protected]8400e032010-02-26 18:50:11284void RenderWidget::OnCreateVideoAck(int32 video_id) {
285 // TODO(scherkus): handle CreateVideo_ACK with a message filter.
286}
287
288void RenderWidget::OnUpdateVideoAck(int32 video_id) {
289 // TODO(scherkus): handle UpdateVideo_ACK with a message filter.
290}
291
initial.commit09911bf2008-07-26 23:55:29292void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
293 void* iter = NULL;
294
295 const char* data;
296 int data_length;
[email protected]5dd768212009-08-13 23:34:49297 handling_input_event_ = true;
298 if (!message.ReadData(&iter, &data, &data_length)) {
299 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29300 return;
[email protected]5dd768212009-08-13 23:34:49301 }
initial.commit09911bf2008-07-26 23:55:29302
303 const WebInputEvent* input_event =
304 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48305
306 bool is_keyboard_shortcut = false;
307 // is_keyboard_shortcut flag is only available for RawKeyDown events.
308 if (input_event->type == WebInputEvent::RawKeyDown)
309 message.ReadBool(&iter, &is_keyboard_shortcut);
310
initial.commit09911bf2008-07-26 23:55:29311 bool processed = false;
[email protected]867125a02009-12-10 06:01:48312 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
313 suppress_next_char_events_ = false;
314 if (webwidget_)
315 processed = webwidget_->handleInputEvent(*input_event);
316 }
317
318 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
319 // it's not processed by webkit, then we need to suppress the upcoming Char
320 // events.
321 if (!processed && is_keyboard_shortcut)
322 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29323
324 IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_);
325 response->WriteInt(input_event->type);
[email protected]e2824412009-02-27 01:57:05326 response->WriteBool(processed);
327
[email protected]12fbad812009-09-01 18:21:24328 if (input_event->type == WebInputEvent::MouseMove &&
[email protected]552e6002009-11-19 05:24:57329 paint_aggregator_.HasPendingUpdate()) {
[email protected]12fbad812009-09-01 18:21:24330 // We want to rate limit the input events in this case, so we'll wait for
331 // painting to finish before ACKing this message.
332 pending_input_event_ack_.reset(response);
333 } else {
334 Send(response);
335 }
336
[email protected]5dd768212009-08-13 23:34:49337 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48338
[email protected]867125a02009-12-10 06:01:48339 if (WebInputEvent::isKeyboardEventType(input_event->type))
[email protected]446705872009-09-10 07:22:48340 DidHandleKeyEvent();
initial.commit09911bf2008-07-26 23:55:29341}
342
343void RenderWidget::OnMouseCaptureLost() {
344 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28345 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29346}
347
348void RenderWidget::OnSetFocus(bool enable) {
349 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33350 if (webwidget_)
351 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29352 if (enable) {
353 // Force to retrieve the state of the focused widget to determine if we
354 // should activate IMEs next time when this process calls the UpdateIME()
355 // function.
356 ime_control_updated_ = true;
357 ime_control_new_state_ = true;
358 }
359}
360
361void RenderWidget::ClearFocus() {
362 // We may have got the focus from the browser before this gets processed, in
363 // which case we do not want to unfocus ourself.
364 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28365 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29366}
367
[email protected]2d5d09d52009-06-15 14:29:21368void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00369 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21370 skia::PlatformCanvas* canvas) {
[email protected]4fb66842009-12-04 21:41:00371 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21372
373 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00374 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
375 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03376
[email protected]699ab0d2009-04-23 23:19:14377 // If there is a custom background, tile it.
378 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14379 SkPaint paint;
380 SkShader* shader = SkShader::CreateBitmapShader(background_,
381 SkShader::kRepeat_TileMode,
382 SkShader::kRepeat_TileMode);
383 paint.setShader(shader)->unref();
[email protected]8860e4f52009-06-25 01:01:52384 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
[email protected]699ab0d2009-04-23 23:19:14385 canvas->drawPaint(paint);
[email protected]699ab0d2009-04-23 23:19:14386 }
387
[email protected]8c89e7792009-08-19 21:18:34388 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
initial.commit09911bf2008-07-26 23:55:29389
[email protected]4fb66842009-12-04 21:41:00390 PaintDebugBorder(rect, canvas);
391
initial.commit09911bf2008-07-26 23:55:29392 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]661eb9d2009-02-03 02:11:48393 canvas->getTopPlatformDevice().accessBitmap(false);
[email protected]4fb66842009-12-04 21:41:00394
395 canvas->restore();
396}
397
398void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
399 skia::PlatformCanvas* canvas) {
400 static bool kPaintBorder =
401 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
402 if (!kPaintBorder)
403 return;
404
[email protected]53d3f302009-12-21 04:42:05405 // Cycle through these colors to help distinguish new paint rects.
406 const SkColor colors[] = {
407 SkColorSetARGB(0x3F, 0xFF, 0, 0),
408 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
409 SkColorSetARGB(0x3F, 0, 0, 0xFF),
410 };
411 static int color_selector = 0;
412
[email protected]4fb66842009-12-04 21:41:00413 SkPaint paint;
414 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05415 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00416 paint.setStrokeWidth(1);
417
418 SkIRect irect;
419 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
420 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29421}
422
[email protected]552e6002009-11-19 05:24:57423void RenderWidget::CallDoDeferredUpdate() {
424 DoDeferredUpdate();
[email protected]12fbad812009-09-01 18:21:24425
426 if (pending_input_event_ack_.get()) {
427 Send(pending_input_event_ack_.get());
428 pending_input_event_ack_.release();
429 }
430}
431
[email protected]552e6002009-11-19 05:24:57432void RenderWidget::DoDeferredUpdate() {
433 if (!webwidget_ || !paint_aggregator_.HasPendingUpdate() ||
[email protected]53d3f302009-12-21 04:42:05434 update_reply_pending())
initial.commit09911bf2008-07-26 23:55:29435 return;
436
[email protected]552e6002009-11-19 05:24:57437 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29438 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57439 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29440 needs_repainting_on_restore_ = true;
441 return;
442 }
443
[email protected]552e6002009-11-19 05:24:57444 // Layout may generate more invalidation.
[email protected]4873c7d2009-07-16 06:36:28445 webwidget_->layout();
initial.commit09911bf2008-07-26 23:55:29446
[email protected]552e6002009-11-19 05:24:57447 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29448 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]552e6002009-11-19 05:24:57449 PaintAggregator::PendingUpdate update = paint_aggregator_.GetPendingUpdate();
450 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29451
[email protected]53d3f302009-12-21 04:42:05452 gfx::Rect scroll_damage = update.GetScrollDamage();
453 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29454
[email protected]53d3f302009-12-21 04:42:05455 // Compute a buffer for painting and cache it.
456 scoped_ptr<skia::PlatformCanvas> canvas(
457 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_, bounds));
458 if (!canvas.get()) {
459 NOTREACHED();
460 return;
[email protected]552e6002009-11-19 05:24:57461 }
462
[email protected]53d3f302009-12-21 04:42:05463 // We may get back a smaller canvas than we asked for.
464 // TODO(darin): This seems like it could cause painting problems!
465 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
466 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
467 bounds.set_width(canvas->getDevice()->width());
468 bounds.set_height(canvas->getDevice()->height());
[email protected]552e6002009-11-19 05:24:57469
[email protected]53d3f302009-12-21 04:42:05470 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
[email protected]552e6002009-11-19 05:24:57471
[email protected]53d3f302009-12-21 04:42:05472 // TODO(darin): Re-enable painting multiple damage rects once the
473 // page-cycler regressions are resolved. See bug 29589.
474 if (update.scroll_rect.IsEmpty()) {
475 update.paint_rects.clear();
476 update.paint_rects.push_back(bounds);
initial.commit09911bf2008-07-26 23:55:29477 }
478
[email protected]cef3362f2009-12-21 17:48:45479 // The scroll damage is just another rectangle to paint and copy.
480 std::vector<gfx::Rect> copy_rects;
481 copy_rects.swap(update.paint_rects);
482 if (!scroll_damage.IsEmpty())
483 copy_rects.push_back(scroll_damage);
484
[email protected]53d3f302009-12-21 04:42:05485 for (size_t i = 0; i < copy_rects.size(); ++i)
486 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
487
488 ViewHostMsg_UpdateRect_Params params;
489 params.bitmap = current_paint_buf_->id();
490 params.bitmap_rect = bounds;
491 params.dx = update.scroll_delta.x();
492 params.dy = update.scroll_delta.y();
493 params.scroll_rect = update.scroll_rect;
494 params.copy_rects.swap(copy_rects); // TODO(darin): clip to bounds?
495 params.view_size = size_;
496 params.plugin_window_moves.swap(plugin_window_moves_);
497 params.flags = next_paint_flags_;
498
499 update_reply_pending_ = true;
500 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
501 next_paint_flags_ = 0;
502
initial.commit09911bf2008-07-26 23:55:29503 UpdateIME();
[email protected]00c39612010-03-06 02:53:28504
505 // Let derived classes know we've painted.
506 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:29507}
508
509///////////////////////////////////////////////////////////////////////////////
510// WebWidgetDelegate
511
[email protected]4873c7d2009-07-16 06:36:28512void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:57513 // We only want one pending DoDeferredUpdate call at any time...
514 bool update_pending = paint_aggregator_.HasPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29515
[email protected]552e6002009-11-19 05:24:57516 // The invalidated rect might be outside the bounds of the view.
[email protected]2d5d09d52009-06-15 14:29:21517 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]552e6002009-11-19 05:24:57518 gfx::Rect damaged_rect = view_rect.Intersect(rect);
519 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29520 return;
521
[email protected]552e6002009-11-19 05:24:57522 paint_aggregator_.InvalidateRect(damaged_rect);
523
524 // We may not need to schedule another call to DoDeferredUpdate.
525 if (update_pending)
526 return;
527 if (!paint_aggregator_.HasPendingUpdate())
528 return;
[email protected]53d3f302009-12-21 04:42:05529 if (update_reply_pending())
[email protected]552e6002009-11-19 05:24:57530 return;
531
532 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:29533 // 1) Ensures that we call WebView::Paint without a bunch of other junk
534 // on the call stack.
535 // 2) Allows us to collect more damage rects before painting to help coalesce
536 // the work that we will need to do.
537 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]552e6002009-11-19 05:24:57538 this, &RenderWidget::CallDoDeferredUpdate));
initial.commit09911bf2008-07-26 23:55:29539}
540
[email protected]4873c7d2009-07-16 06:36:28541void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]552e6002009-11-19 05:24:57542 // We only want one pending DoDeferredUpdate call at any time...
543 bool update_pending = paint_aggregator_.HasPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29544
[email protected]552e6002009-11-19 05:24:57545 // The scrolled rect might be outside the bounds of the view.
546 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
547 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
548 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29549 return;
550
[email protected]552e6002009-11-19 05:24:57551 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
552
553 // We may not need to schedule another call to DoDeferredUpdate.
554 if (update_pending)
555 return;
556 if (!paint_aggregator_.HasPendingUpdate())
557 return;
[email protected]53d3f302009-12-21 04:42:05558 if (update_reply_pending())
[email protected]552e6002009-11-19 05:24:57559 return;
560
561 // Perform updating asynchronously. This serves two purposes:
562 // 1) Ensures that we call WebView::Paint without a bunch of other junk
563 // on the call stack.
564 // 2) Allows us to collect more damage rects before painting to help coalesce
565 // the work that we will need to do.
initial.commit09911bf2008-07-26 23:55:29566 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]552e6002009-11-19 05:24:57567 this, &RenderWidget::CallDoDeferredUpdate));
initial.commit09911bf2008-07-26 23:55:29568}
569
[email protected]4873c7d2009-07-16 06:36:28570void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:30571 // TODO(darin): Eliminate this temporary.
572 WebCursor cursor(cursor_info);
573
initial.commit09911bf2008-07-26 23:55:29574 // Only send a SetCursor message if we need to make a change.
575 if (!current_cursor_.IsEqual(cursor)) {
576 current_cursor_ = cursor;
577 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
578 }
579}
580
581// We are supposed to get a single call to Show for a newly created RenderWidget
582// that was created via RenderWidget::CreateWebView. So, we wait until this
583// point to dispatch the ShowWidget message.
584//
585// This method provides us with the information about how to display the newly
586// created RenderWidget (i.e., as a constrained popup or as a new tab).
587//
[email protected]4873c7d2009-07-16 06:36:28588void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:29589 DCHECK(!did_show_) << "received extraneous Show call";
590 DCHECK(routing_id_ != MSG_ROUTING_NONE);
591 DCHECK(opener_id_ != MSG_ROUTING_NONE);
592
593 if (!did_show_) {
594 did_show_ = true;
595 // NOTE: initial_pos_ may still have its default values at this point, but
596 // that's okay. It'll be ignored if as_popup is false, or the browser
597 // process will impose a default position otherwise.
[email protected]88efb7ec2009-07-14 16:32:59598 if (popup_params_.get()) {
599 popup_params_->bounds = initial_pos_;
600 Send(new ViewHostMsg_ShowPopup(routing_id_, *popup_params_));
601 popup_params_.reset();
602 } else {
603 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
604 }
[email protected]2533ce12009-05-09 00:02:24605 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:29606 }
607}
608
[email protected]4873c7d2009-07-16 06:36:28609void RenderWidget::didFocus() {
[email protected]130efb02009-09-18 18:54:35610 // Note that didFocus() is invoked everytime a new node is focused in the
611 // page. It could be expected that it would be called only when the widget
612 // gets the focus. If the current behavior was to change in WebKit for the
613 // expected one, the following notification would not work anymore.
614 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_));
615
initial.commit09911bf2008-07-26 23:55:29616 // Prevent the widget from stealing the focus if it does not have focus
617 // already. We do this by explicitely setting the focus to false again.
618 // We only let the browser focus the renderer.
619 if (!has_focus_ && webwidget_) {
620 MessageLoop::current()->PostTask(FROM_HERE,
621 NewRunnableMethod(this, &RenderWidget::ClearFocus));
622 }
623}
624
[email protected]4873c7d2009-07-16 06:36:28625void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:29626 Send(new ViewHostMsg_Blur(routing_id_));
627}
628
[email protected]2533ce12009-05-09 00:02:24629void RenderWidget::DoDeferredClose() {
630 Send(new ViewHostMsg_Close(routing_id_));
631}
632
[email protected]4873c7d2009-07-16 06:36:28633void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:29634 // If a page calls window.close() twice, we'll end up here twice, but that's
635 // OK. It is safe to send multiple Close messages.
636
[email protected]2533ce12009-05-09 00:02:24637 // Ask the RenderWidgetHost to initiate close. We could be called from deep
638 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
639 // could be closed before the JS finishes executing. So instead, post a
640 // message back to the message loop, which won't run until the JS is
641 // complete, and then the Close message can be sent.
[email protected]75ae4492009-07-10 00:05:15642 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]2533ce12009-05-09 00:02:24643 this, &RenderWidget::DoDeferredClose));
initial.commit09911bf2008-07-26 23:55:29644}
645
[email protected]b4b967e2009-04-22 11:33:05646void RenderWidget::GenerateFullRepaint() {
[email protected]4873c7d2009-07-16 06:36:28647 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]b4b967e2009-04-22 11:33:05648}
649
initial.commit09911bf2008-07-26 23:55:29650void RenderWidget::Close() {
651 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:28652 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:29653 webwidget_ = NULL;
654 }
655}
656
[email protected]4873c7d2009-07-16 06:36:28657WebRect RenderWidget::windowRect() {
658 if (pending_window_rect_count_)
659 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:24660
[email protected]b3f2b912009-04-09 16:18:52661 gfx::Rect rect;
662 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:28663 return rect;
initial.commit09911bf2008-07-26 23:55:29664}
665
[email protected]4873c7d2009-07-16 06:36:28666void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:29667 if (did_show_) {
668 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:24669 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:29670 } else {
671 initial_pos_ = pos;
672 }
673}
674
[email protected]2533ce12009-05-09 00:02:24675void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
676 pending_window_rect_ = rect;
677 pending_window_rect_count_++;
678}
679
[email protected]4873c7d2009-07-16 06:36:28680WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:24681 if (pending_window_rect_count_) {
682 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
683 // the RootWindowRect is probably going to return wrong results since the
684 // browser may not have processed the Move yet. There isn't really anything
685 // good to do in this case, and it shouldn't happen - since this size is
686 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:28687 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:24688 }
689
[email protected]b3f2b912009-04-09 16:18:52690 gfx::Rect rect;
691 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:28692 return rect;
[email protected]d4547452008-08-28 18:36:37693}
694
[email protected]4873c7d2009-07-16 06:36:28695WebRect RenderWidget::windowResizerRect() {
696 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:19697}
698
initial.commit09911bf2008-07-26 23:55:29699void RenderWidget::OnImeSetInputMode(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:03700 // To prevent this renderer process from sending unnecessary IPC messages to
701 // a browser process, we permit the renderer process to send IPC messages
702 // only during the IME attached to the browser process is active.
initial.commit09911bf2008-07-26 23:55:29703 ime_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:29704}
705
[email protected]4873c7d2009-07-16 06:36:28706void RenderWidget::OnImeSetComposition(WebCompositionCommand command,
initial.commit09911bf2008-07-26 23:55:29707 int cursor_position,
708 int target_start, int target_end,
[email protected]4873c7d2009-07-16 06:36:28709 const string16& ime_string) {
710 if (!webwidget_)
711 return;
712 ime_control_busy_ = true;
[email protected]7f00efa2010-04-15 05:01:26713 if (!webwidget_->handleCompositionEvent(command, cursor_position,
714 target_start, target_end, ime_string)) {
715 // If the composition event can't be handled, let the browser process
716 // know so it can update it's state.
717 Send(new ViewHostMsg_ImeUpdateStatus(routing_id(), IME_CANCEL_COMPOSITION,
718 WebRect()));
719 }
[email protected]4873c7d2009-07-16 06:36:28720 ime_control_busy_ = false;
initial.commit09911bf2008-07-26 23:55:29721}
722
[email protected]ec7dc112008-08-06 05:30:12723void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
724 // During shutdown we can just ignore this message.
725 if (!webwidget_)
726 return;
727
728 set_next_paint_is_repaint_ack();
729 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
[email protected]4873c7d2009-07-16 06:36:28730 didInvalidateRect(repaint_rect);
[email protected]ec7dc112008-08-06 05:30:12731}
732
[email protected]4873c7d2009-07-16 06:36:28733void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:11734 if (!webwidget_)
735 return;
[email protected]4873c7d2009-07-16 06:36:28736 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:11737}
738
[email protected]bee16aab2009-08-26 15:55:03739void RenderWidget::SetHidden(bool hidden) {
740 if (is_hidden_ == hidden)
741 return;
742
743 // The status has changed. Tell the RenderThread about it.
744 is_hidden_ = hidden;
745 if (is_hidden_)
746 render_thread_->WidgetHidden();
747 else
748 render_thread_->WidgetRestored();
749}
750
[email protected]699ab0d2009-04-23 23:19:14751void RenderWidget::SetBackground(const SkBitmap& background) {
752 background_ = background;
753 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:28754 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:14755}
756
[email protected]674741932009-02-04 23:44:46757bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:05758 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:46759}
760
761bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:05762 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:46763}
764
765void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:05766 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:46767}
768
769void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:05770 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:46771}
772
773void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:05774 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:46775}
776
initial.commit09911bf2008-07-26 23:55:29777void RenderWidget::UpdateIME() {
778 // If a browser process does not have IMEs, its IMEs are not active, or there
779 // are not any attached widgets.
780 // a renderer process does not have to retrieve information of the focused
781 // control or send notification messages to a browser process.
782 if (!ime_is_active_) {
783 return;
784 }
[email protected]34f6bc12008-11-06 07:40:53785 // Retrieve the caret position from the focused widget and verify we should
786 // enabled IMEs attached to the browser process.
787 bool enable_ime = false;
[email protected]b3f2b912009-04-09 16:18:52788 WebRect caret_rect;
[email protected]34f6bc12008-11-06 07:40:53789 if (!webwidget_ ||
[email protected]4873c7d2009-07-16 06:36:28790 !webwidget_->queryCompositionStatus(&enable_ime, &caret_rect)) {
initial.commit09911bf2008-07-26 23:55:29791 // There are not any editable widgets attached to this process.
792 // We should disable the IME to prevent it from sending CJK strings to
793 // non-editable widgets.
794 ime_control_updated_ = true;
795 ime_control_new_state_ = false;
796 }
[email protected]9f23f592008-11-17 08:36:34797 if (ime_control_new_state_ != enable_ime) {
798 ime_control_updated_ = true;
799 ime_control_new_state_ = enable_ime;
800 }
initial.commit09911bf2008-07-26 23:55:29801 if (ime_control_updated_) {
802 // The input focus has been changed.
803 // Compare the current state with the updated state and choose actions.
804 if (ime_control_enable_ime_) {
805 if (ime_control_new_state_) {
806 // Case 1: a text input -> another text input
807 // Complete the current composition and notify the caret position.
[email protected]34f6bc12008-11-06 07:40:53808 Send(new ViewHostMsg_ImeUpdateStatus(routing_id(),
809 IME_COMPLETE_COMPOSITION,
810 caret_rect));
initial.commit09911bf2008-07-26 23:55:29811 } else {
812 // Case 2: a text input -> a password input (or a static control)
813 // Complete the current composition and disable the IME.
[email protected]34f6bc12008-11-06 07:40:53814 Send(new ViewHostMsg_ImeUpdateStatus(routing_id(), IME_DISABLE,
815 caret_rect));
initial.commit09911bf2008-07-26 23:55:29816 }
817 } else {
818 if (ime_control_new_state_) {
819 // Case 3: a password input (or a static control) -> a text input
820 // Enable the IME and notify the caret position.
[email protected]34f6bc12008-11-06 07:40:53821 Send(new ViewHostMsg_ImeUpdateStatus(routing_id(),
822 IME_COMPLETE_COMPOSITION,
823 caret_rect));
initial.commit09911bf2008-07-26 23:55:29824 } else {
825 // Case 4: a password input (or a static contol) -> another password
826 // input (or another static control).
827 // The IME has been already disabled and we don't have to do anything.
828 }
829 }
830 } else {
831 // The input focus is not changed.
832 // Notify the caret position to a browser process only if it is changed.
833 if (ime_control_enable_ime_) {
[email protected]b3f2b912009-04-09 16:18:52834 if (caret_rect.x != ime_control_x_ ||
835 caret_rect.y != ime_control_y_) {
[email protected]34f6bc12008-11-06 07:40:53836 Send(new ViewHostMsg_ImeUpdateStatus(routing_id(), IME_MOVE_WINDOWS,
837 caret_rect));
initial.commit09911bf2008-07-26 23:55:29838 }
839 }
840 }
841 // Save the updated IME status to prevent from sending the same IPC messages.
842 ime_control_updated_ = false;
843 ime_control_enable_ime_ = ime_control_new_state_;
[email protected]b3f2b912009-04-09 16:18:52844 ime_control_x_ = caret_rect.x;
845 ime_control_y_ = caret_rect.y;
initial.commit09911bf2008-07-26 23:55:29846}
847
[email protected]4873c7d2009-07-16 06:36:28848WebScreenInfo RenderWidget::screenInfo() {
849 WebScreenInfo results;
850 Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results));
851 return results;
852}
853
[email protected]f103ab72009-09-02 17:10:59854void RenderWidget::SchedulePluginMove(
855 const webkit_glue::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:29856 size_t i = 0;
857 for (; i < plugin_window_moves_.size(); ++i) {
858 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:58859 if (move.rects_valid) {
860 plugin_window_moves_[i] = move;
861 } else {
862 plugin_window_moves_[i].visible = move.visible;
863 }
initial.commit09911bf2008-07-26 23:55:29864 break;
865 }
866 }
867
868 if (i == plugin_window_moves_.size())
869 plugin_window_moves_.push_back(move);
870}
[email protected]268654772009-08-06 23:02:04871
872void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
873 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
874 i != plugin_window_moves_.end(); ++i) {
875 if (i->window == window) {
876 plugin_window_moves_.erase(i);
877 break;
878 }
879 }
880}
[email protected]246a70452010-03-05 21:53:50881