blob: 9387230846cc67e5188c6ffdf776914861dbf861 [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"
[email protected]7a4de7a62010-08-17 18:38:2410#include "base/histogram.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/message_loop.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/scoped_ptr.h"
[email protected]661eb9d2009-02-03 02:11:4813#include "build/build_config.h"
[email protected]4fb66842009-12-04 21:41:0014#include "chrome/common/chrome_switches.h"
[email protected]674741932009-02-04 23:44:4615#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0216#include "chrome/common/render_messages_params.h"
[email protected]8085dbc82008-09-26 22:53:4417#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2818#include "chrome/renderer/render_thread.h"
[email protected]e0fc2f12010-03-14 23:30:5919#include "gfx/point.h"
20#include "gfx/size.h"
[email protected]484955942010-08-19 16:13:1821#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4822#include "skia/ext/platform_canvas.h"
[email protected]d5282e72009-05-13 13:16:5223#include "third_party/skia/include/core/SkShader.h"
[email protected]418ed5ab2009-11-12 01:14:4924#include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h"
25#include "third_party/WebKit/WebKit/chromium/public/WebPopupMenu.h"
26#include "third_party/WebKit/WebKit/chromium/public/WebPopupMenuInfo.h"
27#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
28#include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h"
29#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]7a4de7a62010-08-17 18:38:2430#include "webkit/glue/plugins/webplugin.h"
[email protected]8c89e7792009-08-19 21:18:3431#include "webkit/glue/webkit_glue.h"
[email protected]661eb9d2009-02-03 02:11:4832
33#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4934#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5235#include "third_party/skia/include/core/SkPixelRef.h"
36#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4837#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4438
[email protected]418ed5ab2009-11-12 01:14:4939#include "third_party/WebKit/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2940
[email protected]fa7b1dc2010-06-23 17:53:0441using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3042using WebKit::WebCursorInfo;
[email protected]62cb33cae2009-03-27 23:30:2243using WebKit::WebInputEvent;
[email protected]4873c7d2009-07-16 06:36:2844using WebKit::WebNavigationPolicy;
45using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5946using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1847using WebKit::WebPopupType;
[email protected]b3f2b912009-04-09 16:18:5248using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1949using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5250using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2851using WebKit::WebTextDirection;
[email protected]fa7b1dc2010-06-23 17:53:0452using WebKit::WebTextInputType;
53using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1854using WebKit::WebWidget;
[email protected]62cb33cae2009-03-27 23:30:2255
[email protected]3e2b375b2010-04-07 17:03:1256RenderWidget::RenderWidget(RenderThreadBase* render_thread,
57 WebKit::WebPopupType popup_type)
initial.commit09911bf2008-07-26 23:55:2958 : routing_id_(MSG_ROUTING_NONE),
[email protected]c5b3b5e2009-02-13 06:41:1159 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2960 opener_id_(MSG_ROUTING_NONE),
[email protected]8085dbc82008-09-26 22:53:4461 render_thread_(render_thread),
[email protected]659f73f2009-10-13 13:43:4262 host_window_(0),
initial.commit09911bf2008-07-26 23:55:2963 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2964 next_paint_flags_(0),
[email protected]53d3f302009-12-21 04:42:0565 update_reply_pending_(false),
initial.commit09911bf2008-07-26 23:55:2966 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2967 is_hidden_(false),
68 needs_repainting_on_restore_(false),
69 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4970 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4871 closing_(false),
[email protected]fa7b1dc2010-06-23 17:53:0472 input_method_is_active_(false),
73 text_input_type_(WebKit::WebTextInputTypeNone),
[email protected]3e2b375b2010-04-07 17:03:1274 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:4875 pending_window_rect_count_(0),
[email protected]edbcde932010-05-07 17:10:4676 suppress_next_char_events_(false),
77 is_gpu_rendering_active_(false) {
[email protected]8930d472009-02-21 08:05:2878 RenderProcess::current()->AddRefProcess();
[email protected]8085dbc82008-09-26 22:53:4479 DCHECK(render_thread_);
initial.commit09911bf2008-07-26 23:55:2980}
81
82RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:1183 DCHECK(!webwidget_) << "Leaking our WebWidget!";
initial.commit09911bf2008-07-26 23:55:2984 if (current_paint_buf_) {
[email protected]8930d472009-02-21 08:05:2885 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
initial.commit09911bf2008-07-26 23:55:2986 current_paint_buf_ = NULL;
87 }
[email protected]8930d472009-02-21 08:05:2888 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:2989}
90
[email protected]484955942010-08-19 16:13:1891// static
[email protected]8085dbc82008-09-26 22:53:4492RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]0ebf3872008-11-07 21:35:0393 RenderThreadBase* render_thread,
[email protected]3e2b375b2010-04-07 17:03:1294 WebKit::WebPopupType popup_type) {
initial.commit09911bf2008-07-26 23:55:2995 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]0ebf3872008-11-07 21:35:0396 scoped_refptr<RenderWidget> widget = new RenderWidget(render_thread,
[email protected]3e2b375b2010-04-07 17:03:1297 popup_type);
initial.commit09911bf2008-07-26 23:55:2998 widget->Init(opener_id); // adds reference
99 return widget;
100}
101
[email protected]484955942010-08-19 16:13:18102// static
103WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
104 switch (render_widget->popup_type_) {
105 case WebKit::WebPopupTypeNone: // Nothing to create.
106 break;
107 case WebKit::WebPopupTypeSelect:
108 case WebKit::WebPopupTypeSuggestion:
109 return WebPopupMenu::create(render_widget);
110 default:
111 NOTREACHED();
112 }
113 return NULL;
114}
115
[email protected]88efb7ec2009-07-14 16:32:59116void RenderWidget::ConfigureAsExternalPopupMenu(const WebPopupMenuInfo& info) {
117 popup_params_.reset(new ViewHostMsg_ShowPopup_Params);
118 popup_params_->item_height = info.itemHeight;
[email protected]c9e19792010-03-17 17:02:59119 popup_params_->item_font_size = info.itemFontSize;
[email protected]88efb7ec2009-07-14 16:32:59120 popup_params_->selected_item = info.selectedIndex;
121 for (size_t i = 0; i < info.items.size(); ++i)
122 popup_params_->popup_items.push_back(WebMenuItem(info.items[i]));
[email protected]b88ab032010-05-13 22:13:04123 popup_params_->right_aligned = info.rightAligned;
[email protected]88efb7ec2009-07-14 16:32:59124}
125
initial.commit09911bf2008-07-26 23:55:29126void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18127 DoInit(opener_id,
128 RenderWidget::CreateWebWidget(this),
129 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
130}
131
132
133void RenderWidget::DoInit(int32 opener_id,
134 WebKit::WebWidget* web_widget,
135 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29136 DCHECK(!webwidget_);
137
138 if (opener_id != MSG_ROUTING_NONE)
139 opener_id_ = opener_id;
140
[email protected]484955942010-08-19 16:13:18141 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29142
[email protected]484955942010-08-19 16:13:18143 bool result = render_thread_->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29144 if (result) {
[email protected]8085dbc82008-09-26 22:53:44145 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29146 // Take a reference on behalf of the RenderThread. This will be balanced
147 // when we receive ViewMsg_Close.
148 AddRef();
149 } else {
150 DCHECK(false);
151 }
152}
153
154// This is used to complete pending inits and non-pending inits. For non-
155// pending cases, the parent will be the same as the current parent. This
156// indicates we do not need to reparent or anything.
[email protected]18bcc3c2009-01-27 21:39:15157void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29158 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29159
160 host_window_ = parent_hwnd;
161
[email protected]6de74452009-02-25 18:04:59162 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29163}
164
165IPC_DEFINE_MESSAGE_MAP(RenderWidget)
166 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
167 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
168 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
169 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
170 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]53d3f302009-12-21 04:42:05171 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]8400e032010-02-26 18:50:11172 IPC_MESSAGE_HANDLER(ViewMsg_CreateVideo_ACK, OnCreateVideoAck)
173 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVideo_ACK, OnUpdateVideoAck)
initial.commit09911bf2008-07-26 23:55:29174 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
175 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
176 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
[email protected]fa7b1dc2010-06-23 17:53:04177 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
initial.commit09911bf2008-07-26 23:55:29178 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
[email protected]fa7b1dc2010-06-23 17:53:04179 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]d65adb12010-04-28 17:26:49180 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
[email protected]ec7dc112008-08-06 05:30:12181 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
[email protected]07f953332009-03-25 04:31:11182 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
[email protected]2533ce12009-05-09 00:02:24183 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
initial.commit09911bf2008-07-26 23:55:29184 IPC_MESSAGE_UNHANDLED_ERROR()
185IPC_END_MESSAGE_MAP()
186
187bool RenderWidget::Send(IPC::Message* message) {
188 // Don't send any messages after the browser has told us to close.
189 if (closing_) {
190 delete message;
191 return false;
192 }
193
194 // If given a messsage without a routing ID, then assign our routing ID.
195 if (message->routing_id() == MSG_ROUTING_NONE)
196 message->set_routing_id(routing_id_);
197
[email protected]d3fc25652009-02-24 22:31:25198 return render_thread_->Send(message);
[email protected]8085dbc82008-09-26 22:53:44199}
200
initial.commit09911bf2008-07-26 23:55:29201// Got a response from the browser after the renderer decided to create a new
202// view.
[email protected]18bcc3c2009-01-27 21:39:15203void RenderWidget::OnCreatingNewAck(gfx::NativeViewId parent) {
initial.commit09911bf2008-07-26 23:55:29204 DCHECK(routing_id_ != MSG_ROUTING_NONE);
205
206 CompleteInit(parent);
207}
208
209void RenderWidget::OnClose() {
210 if (closing_)
211 return;
212 closing_ = true;
213
214 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03215 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]8085dbc82008-09-26 22:53:44216 render_thread_->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03217 SetHidden(false);
218 }
initial.commit09911bf2008-07-26 23:55:29219
initial.commit09911bf2008-07-26 23:55:29220 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25221 // now. Post a task that only gets invoked when there are no nested message
222 // loops.
223 MessageLoop::current()->PostNonNestableTask(FROM_HERE,
224 NewRunnableMethod(this, &RenderWidget::Close));
225
226 // Balances the AddRef taken when we called AddRoute.
227 Release();
initial.commit09911bf2008-07-26 23:55:29228}
229
[email protected]f21c613a2009-02-12 14:46:17230void RenderWidget::OnResize(const gfx::Size& new_size,
231 const gfx::Rect& resizer_rect) {
initial.commit09911bf2008-07-26 23:55:29232 // During shutdown we can just ignore this message.
233 if (!webwidget_)
234 return;
235
[email protected]f21c613a2009-02-12 14:46:17236 // Remember the rect where the resize corner will be drawn.
237 resizer_rect_ = resizer_rect;
238
initial.commit09911bf2008-07-26 23:55:29239 // TODO(darin): We should not need to reset this here.
[email protected]bee16aab2009-08-26 15:55:03240 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29241 needs_repainting_on_restore_ = false;
242
243 // We shouldn't be asked to resize to our current size.
244 DCHECK(size_ != new_size);
245 size_ = new_size;
246
247 // We should not be sent a Resize message if we have not ACK'd the previous
248 DCHECK(!next_paint_is_resize_ack());
249
[email protected]552e6002009-11-19 05:24:57250 paint_aggregator_.ClearPendingUpdate();
251
initial.commit09911bf2008-07-26 23:55:29252 // When resizing, we want to wait to paint before ACK'ing the resize. This
253 // ensures that we only resize as fast as we can paint. We only need to send
254 // an ACK if we are resized to a non-empty rect.
[email protected]4873c7d2009-07-16 06:36:28255 webwidget_->resize(new_size);
initial.commit09911bf2008-07-26 23:55:29256 if (!new_size.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57257 // Resize should have caused an invalidation of the entire view.
258 DCHECK(paint_aggregator_.HasPendingUpdate());
[email protected]2d5d09d52009-06-15 14:29:21259
initial.commit09911bf2008-07-26 23:55:29260 // We will send the Resize_ACK flag once we paint again.
261 set_next_paint_is_resize_ack();
262 }
263}
264
265void RenderWidget::OnWasHidden() {
266 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03267 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29268}
269
270void RenderWidget::OnWasRestored(bool needs_repainting) {
271 // During shutdown we can just ignore this message.
272 if (!webwidget_)
273 return;
274
275 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03276 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29277
278 if (!needs_repainting && !needs_repainting_on_restore_)
279 return;
280 needs_repainting_on_restore_ = false;
281
[email protected]d65adb12010-04-28 17:26:49282 // Tag the next paint as a restore ack, which is picked up by
283 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29284 set_next_paint_is_restore_ack();
285
286 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:28287 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
initial.commit09911bf2008-07-26 23:55:29288}
289
[email protected]53d3f302009-12-21 04:42:05290void RenderWidget::OnRequestMoveAck() {
291 DCHECK(pending_window_rect_count_);
292 pending_window_rect_count_--;
293}
294
295void RenderWidget::OnUpdateRectAck() {
296 DCHECK(update_reply_pending());
297 update_reply_pending_ = false;
298
299 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
[email protected]d65adb12010-04-28 17:26:49300 // have no current paint buffer.
[email protected]b7fce1f2008-08-14 05:01:07301 if (current_paint_buf_) {
[email protected]8930d472009-02-21 08:05:28302 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
[email protected]b7fce1f2008-08-14 05:01:07303 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29304 }
[email protected]e68e62fa2009-02-20 02:00:04305
[email protected]00c39612010-03-06 02:53:28306 // Notify subclasses.
307 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25308
initial.commit09911bf2008-07-26 23:55:29309 // Continue painting if necessary...
[email protected]552e6002009-11-19 05:24:57310 CallDoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29311}
312
[email protected]8400e032010-02-26 18:50:11313void RenderWidget::OnCreateVideoAck(int32 video_id) {
314 // TODO(scherkus): handle CreateVideo_ACK with a message filter.
315}
316
317void RenderWidget::OnUpdateVideoAck(int32 video_id) {
318 // TODO(scherkus): handle UpdateVideo_ACK with a message filter.
319}
320
initial.commit09911bf2008-07-26 23:55:29321void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
322 void* iter = NULL;
323
324 const char* data;
325 int data_length;
[email protected]5dd768212009-08-13 23:34:49326 handling_input_event_ = true;
327 if (!message.ReadData(&iter, &data, &data_length)) {
328 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29329 return;
[email protected]5dd768212009-08-13 23:34:49330 }
initial.commit09911bf2008-07-26 23:55:29331
332 const WebInputEvent* input_event =
333 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48334
335 bool is_keyboard_shortcut = false;
336 // is_keyboard_shortcut flag is only available for RawKeyDown events.
337 if (input_event->type == WebInputEvent::RawKeyDown)
338 message.ReadBool(&iter, &is_keyboard_shortcut);
339
initial.commit09911bf2008-07-26 23:55:29340 bool processed = false;
[email protected]867125a02009-12-10 06:01:48341 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
342 suppress_next_char_events_ = false;
343 if (webwidget_)
344 processed = webwidget_->handleInputEvent(*input_event);
345 }
346
347 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
348 // it's not processed by webkit, then we need to suppress the upcoming Char
349 // events.
350 if (!processed && is_keyboard_shortcut)
351 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29352
353 IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_);
354 response->WriteInt(input_event->type);
[email protected]e2824412009-02-27 01:57:05355 response->WriteBool(processed);
356
[email protected]353a34c2010-05-28 23:35:17357 if ((input_event->type == WebInputEvent::MouseMove ||
358 input_event->type == WebInputEvent::MouseWheel) &&
[email protected]552e6002009-11-19 05:24:57359 paint_aggregator_.HasPendingUpdate()) {
[email protected]12fbad812009-09-01 18:21:24360 // We want to rate limit the input events in this case, so we'll wait for
361 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17362 if (pending_input_event_ack_.get()) {
363 // As two different kinds of events could cause us to postpone an ack
364 // we send it now, if we have one pending. The Browser should never
365 // send us the same kind of event we are delaying the ack for.
366 Send(pending_input_event_ack_.release());
367 }
[email protected]12fbad812009-09-01 18:21:24368 pending_input_event_ack_.reset(response);
369 } else {
370 Send(response);
371 }
372
[email protected]5dd768212009-08-13 23:34:49373 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48374
[email protected]867125a02009-12-10 06:01:48375 if (WebInputEvent::isKeyboardEventType(input_event->type))
[email protected]446705872009-09-10 07:22:48376 DidHandleKeyEvent();
initial.commit09911bf2008-07-26 23:55:29377}
378
379void RenderWidget::OnMouseCaptureLost() {
380 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28381 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29382}
383
384void RenderWidget::OnSetFocus(bool enable) {
385 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33386 if (webwidget_)
387 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29388}
389
390void RenderWidget::ClearFocus() {
391 // We may have got the focus from the browser before this gets processed, in
392 // which case we do not want to unfocus ourself.
393 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28394 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29395}
396
[email protected]2d5d09d52009-06-15 14:29:21397void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00398 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21399 skia::PlatformCanvas* canvas) {
[email protected]4fb66842009-12-04 21:41:00400 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21401
402 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00403 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
404 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03405
[email protected]699ab0d2009-04-23 23:19:14406 // If there is a custom background, tile it.
407 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14408 SkPaint paint;
409 SkShader* shader = SkShader::CreateBitmapShader(background_,
410 SkShader::kRepeat_TileMode,
411 SkShader::kRepeat_TileMode);
412 paint.setShader(shader)->unref();
[email protected]8860e4f52009-06-25 01:01:52413 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
[email protected]699ab0d2009-04-23 23:19:14414 canvas->drawPaint(paint);
[email protected]699ab0d2009-04-23 23:19:14415 }
416
[email protected]01b47232010-07-01 20:33:47417 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
initial.commit09911bf2008-07-26 23:55:29418
[email protected]4fb66842009-12-04 21:41:00419 PaintDebugBorder(rect, canvas);
420
initial.commit09911bf2008-07-26 23:55:29421 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]661eb9d2009-02-03 02:11:48422 canvas->getTopPlatformDevice().accessBitmap(false);
[email protected]4fb66842009-12-04 21:41:00423
424 canvas->restore();
425}
426
427void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
428 skia::PlatformCanvas* canvas) {
429 static bool kPaintBorder =
430 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
431 if (!kPaintBorder)
432 return;
433
[email protected]53d3f302009-12-21 04:42:05434 // Cycle through these colors to help distinguish new paint rects.
435 const SkColor colors[] = {
436 SkColorSetARGB(0x3F, 0xFF, 0, 0),
437 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
438 SkColorSetARGB(0x3F, 0, 0, 0xFF),
439 };
440 static int color_selector = 0;
441
[email protected]4fb66842009-12-04 21:41:00442 SkPaint paint;
443 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05444 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00445 paint.setStrokeWidth(1);
446
447 SkIRect irect;
448 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
449 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29450}
451
[email protected]552e6002009-11-19 05:24:57452void RenderWidget::CallDoDeferredUpdate() {
453 DoDeferredUpdate();
[email protected]12fbad812009-09-01 18:21:24454
[email protected]d22d8732010-05-04 19:24:42455 if (pending_input_event_ack_.get())
456 Send(pending_input_event_ack_.release());
[email protected]12fbad812009-09-01 18:21:24457}
458
[email protected]552e6002009-11-19 05:24:57459void RenderWidget::DoDeferredUpdate() {
460 if (!webwidget_ || !paint_aggregator_.HasPendingUpdate() ||
[email protected]53d3f302009-12-21 04:42:05461 update_reply_pending())
initial.commit09911bf2008-07-26 23:55:29462 return;
463
[email protected]552e6002009-11-19 05:24:57464 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29465 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57466 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29467 needs_repainting_on_restore_ = true;
468 return;
469 }
470
[email protected]edbcde932010-05-07 17:10:46471 // If we are using accelerated compositing then all the drawing
472 // to the associated window happens directly from the gpu process and the
473 // browser process shouldn't do any drawing.
474 // TODO(vangelis): Currently the accelerated compositing path relies on
475 // invalidating parts of the page so that we get a request to redraw.
476 // This needs to change to a model where the compositor updates the
477 // contents of the page independently and the browser process gets no
478 // longer involved.
479 if (webwidget_->isAcceleratedCompositingActive() !=
480 is_gpu_rendering_active_) {
481 is_gpu_rendering_active_ = webwidget_->isAcceleratedCompositingActive();
482 Send(new ViewHostMsg_GpuRenderingActivated(
483 routing_id_, is_gpu_rendering_active_));
484 }
485
[email protected]552e6002009-11-19 05:24:57486 // Layout may generate more invalidation.
[email protected]4873c7d2009-07-16 06:36:28487 webwidget_->layout();
initial.commit09911bf2008-07-26 23:55:29488
[email protected]552e6002009-11-19 05:24:57489 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29490 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]552e6002009-11-19 05:24:57491 PaintAggregator::PendingUpdate update = paint_aggregator_.GetPendingUpdate();
492 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29493
[email protected]53d3f302009-12-21 04:42:05494 gfx::Rect scroll_damage = update.GetScrollDamage();
495 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29496
[email protected]53d3f302009-12-21 04:42:05497 // Compute a buffer for painting and cache it.
498 scoped_ptr<skia::PlatformCanvas> canvas(
499 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_, bounds));
500 if (!canvas.get()) {
501 NOTREACHED();
502 return;
[email protected]552e6002009-11-19 05:24:57503 }
504
[email protected]53d3f302009-12-21 04:42:05505 // We may get back a smaller canvas than we asked for.
506 // TODO(darin): This seems like it could cause painting problems!
507 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
508 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
509 bounds.set_width(canvas->getDevice()->width());
510 bounds.set_height(canvas->getDevice()->height());
[email protected]552e6002009-11-19 05:24:57511
[email protected]53d3f302009-12-21 04:42:05512 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
[email protected]552e6002009-11-19 05:24:57513
[email protected]53d3f302009-12-21 04:42:05514 // TODO(darin): Re-enable painting multiple damage rects once the
515 // page-cycler regressions are resolved. See bug 29589.
516 if (update.scroll_rect.IsEmpty()) {
517 update.paint_rects.clear();
518 update.paint_rects.push_back(bounds);
initial.commit09911bf2008-07-26 23:55:29519 }
520
[email protected]cef3362f2009-12-21 17:48:45521 // The scroll damage is just another rectangle to paint and copy.
522 std::vector<gfx::Rect> copy_rects;
523 copy_rects.swap(update.paint_rects);
524 if (!scroll_damage.IsEmpty())
525 copy_rects.push_back(scroll_damage);
526
[email protected]53d3f302009-12-21 04:42:05527 for (size_t i = 0; i < copy_rects.size(); ++i)
528 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
529
530 ViewHostMsg_UpdateRect_Params params;
531 params.bitmap = current_paint_buf_->id();
532 params.bitmap_rect = bounds;
533 params.dx = update.scroll_delta.x();
534 params.dy = update.scroll_delta.y();
[email protected]b167ca662010-05-14 00:05:34535 if (is_gpu_rendering_active_) {
536 // If painting is done via the gpu process then we clear out all damage
537 // rects to save the browser process from doing unecessary work.
538 params.scroll_rect = gfx::Rect();
539 params.copy_rects.clear();
540 } else {
541 params.scroll_rect = update.scroll_rect;
542 params.copy_rects.swap(copy_rects); // TODO(darin): clip to bounds?
543 }
[email protected]53d3f302009-12-21 04:42:05544 params.view_size = size_;
545 params.plugin_window_moves.swap(plugin_window_moves_);
546 params.flags = next_paint_flags_;
547
548 update_reply_pending_ = true;
549 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
550 next_paint_flags_ = 0;
551
[email protected]fa7b1dc2010-06-23 17:53:04552 UpdateInputMethod();
[email protected]00c39612010-03-06 02:53:28553
554 // Let derived classes know we've painted.
555 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:29556}
557
558///////////////////////////////////////////////////////////////////////////////
559// WebWidgetDelegate
560
[email protected]4873c7d2009-07-16 06:36:28561void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:57562 // We only want one pending DoDeferredUpdate call at any time...
563 bool update_pending = paint_aggregator_.HasPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29564
[email protected]552e6002009-11-19 05:24:57565 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48566 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57567 gfx::Rect damaged_rect = view_rect.Intersect(rect);
568 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29569 return;
570
[email protected]552e6002009-11-19 05:24:57571 paint_aggregator_.InvalidateRect(damaged_rect);
572
573 // We may not need to schedule another call to DoDeferredUpdate.
574 if (update_pending)
575 return;
576 if (!paint_aggregator_.HasPendingUpdate())
577 return;
[email protected]53d3f302009-12-21 04:42:05578 if (update_reply_pending())
[email protected]552e6002009-11-19 05:24:57579 return;
580
581 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:29582 // 1) Ensures that we call WebView::Paint without a bunch of other junk
583 // on the call stack.
584 // 2) Allows us to collect more damage rects before painting to help coalesce
585 // the work that we will need to do.
586 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]552e6002009-11-19 05:24:57587 this, &RenderWidget::CallDoDeferredUpdate));
initial.commit09911bf2008-07-26 23:55:29588}
589
[email protected]4873c7d2009-07-16 06:36:28590void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]552e6002009-11-19 05:24:57591 // We only want one pending DoDeferredUpdate call at any time...
592 bool update_pending = paint_aggregator_.HasPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29593
[email protected]552e6002009-11-19 05:24:57594 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48595 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57596 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
597 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29598 return;
599
[email protected]552e6002009-11-19 05:24:57600 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
601
602 // We may not need to schedule another call to DoDeferredUpdate.
603 if (update_pending)
604 return;
605 if (!paint_aggregator_.HasPendingUpdate())
606 return;
[email protected]53d3f302009-12-21 04:42:05607 if (update_reply_pending())
[email protected]552e6002009-11-19 05:24:57608 return;
609
610 // Perform updating asynchronously. This serves two purposes:
611 // 1) Ensures that we call WebView::Paint without a bunch of other junk
612 // on the call stack.
613 // 2) Allows us to collect more damage rects before painting to help coalesce
614 // the work that we will need to do.
initial.commit09911bf2008-07-26 23:55:29615 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]552e6002009-11-19 05:24:57616 this, &RenderWidget::CallDoDeferredUpdate));
initial.commit09911bf2008-07-26 23:55:29617}
618
[email protected]4873c7d2009-07-16 06:36:28619void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:30620 // TODO(darin): Eliminate this temporary.
621 WebCursor cursor(cursor_info);
622
initial.commit09911bf2008-07-26 23:55:29623 // Only send a SetCursor message if we need to make a change.
624 if (!current_cursor_.IsEqual(cursor)) {
625 current_cursor_ = cursor;
626 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
627 }
628}
629
630// We are supposed to get a single call to Show for a newly created RenderWidget
631// that was created via RenderWidget::CreateWebView. So, we wait until this
632// point to dispatch the ShowWidget message.
633//
634// This method provides us with the information about how to display the newly
635// created RenderWidget (i.e., as a constrained popup or as a new tab).
636//
[email protected]4873c7d2009-07-16 06:36:28637void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:29638 DCHECK(!did_show_) << "received extraneous Show call";
639 DCHECK(routing_id_ != MSG_ROUTING_NONE);
640 DCHECK(opener_id_ != MSG_ROUTING_NONE);
641
642 if (!did_show_) {
643 did_show_ = true;
644 // NOTE: initial_pos_ may still have its default values at this point, but
645 // that's okay. It'll be ignored if as_popup is false, or the browser
646 // process will impose a default position otherwise.
[email protected]88efb7ec2009-07-14 16:32:59647 if (popup_params_.get()) {
648 popup_params_->bounds = initial_pos_;
649 Send(new ViewHostMsg_ShowPopup(routing_id_, *popup_params_));
650 popup_params_.reset();
651 } else {
652 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
653 }
[email protected]2533ce12009-05-09 00:02:24654 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:29655 }
656}
657
[email protected]4873c7d2009-07-16 06:36:28658void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:29659}
660
[email protected]4873c7d2009-07-16 06:36:28661void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:29662}
663
[email protected]2533ce12009-05-09 00:02:24664void RenderWidget::DoDeferredClose() {
665 Send(new ViewHostMsg_Close(routing_id_));
666}
667
[email protected]4873c7d2009-07-16 06:36:28668void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:29669 // If a page calls window.close() twice, we'll end up here twice, but that's
670 // OK. It is safe to send multiple Close messages.
671
[email protected]2533ce12009-05-09 00:02:24672 // Ask the RenderWidgetHost to initiate close. We could be called from deep
673 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
674 // could be closed before the JS finishes executing. So instead, post a
675 // message back to the message loop, which won't run until the JS is
676 // complete, and then the Close message can be sent.
[email protected]75ae4492009-07-10 00:05:15677 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]2533ce12009-05-09 00:02:24678 this, &RenderWidget::DoDeferredClose));
initial.commit09911bf2008-07-26 23:55:29679}
680
[email protected]b4b967e2009-04-22 11:33:05681void RenderWidget::GenerateFullRepaint() {
[email protected]4873c7d2009-07-16 06:36:28682 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]b4b967e2009-04-22 11:33:05683}
684
initial.commit09911bf2008-07-26 23:55:29685void RenderWidget::Close() {
686 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:28687 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:29688 webwidget_ = NULL;
689 }
690}
691
[email protected]4873c7d2009-07-16 06:36:28692WebRect RenderWidget::windowRect() {
693 if (pending_window_rect_count_)
694 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:24695
[email protected]b3f2b912009-04-09 16:18:52696 gfx::Rect rect;
697 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:28698 return rect;
initial.commit09911bf2008-07-26 23:55:29699}
700
[email protected]4873c7d2009-07-16 06:36:28701void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:29702 if (did_show_) {
703 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:24704 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:29705 } else {
706 initial_pos_ = pos;
707 }
708}
709
[email protected]2533ce12009-05-09 00:02:24710void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
711 pending_window_rect_ = rect;
712 pending_window_rect_count_++;
713}
714
[email protected]4873c7d2009-07-16 06:36:28715WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:24716 if (pending_window_rect_count_) {
717 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
718 // the RootWindowRect is probably going to return wrong results since the
719 // browser may not have processed the Move yet. There isn't really anything
720 // good to do in this case, and it shouldn't happen - since this size is
721 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:28722 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:24723 }
724
[email protected]b3f2b912009-04-09 16:18:52725 gfx::Rect rect;
726 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:28727 return rect;
[email protected]d4547452008-08-28 18:36:37728}
729
[email protected]4873c7d2009-07-16 06:36:28730WebRect RenderWidget::windowResizerRect() {
731 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:19732}
733
[email protected]fa7b1dc2010-06-23 17:53:04734void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:03735 // To prevent this renderer process from sending unnecessary IPC messages to
736 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:04737 // only during the input method attached to the browser process is active.
738 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:29739}
740
[email protected]fa7b1dc2010-06-23 17:53:04741void RenderWidget::OnImeSetComposition(
742 const string16& text,
743 const std::vector<WebCompositionUnderline>& underlines,
744 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:28745 if (!webwidget_)
746 return;
[email protected]fa7b1dc2010-06-23 17:53:04747 if (!webwidget_->setComposition(
748 text, WebVector<WebCompositionUnderline>(underlines),
749 selection_start, selection_end)) {
750 // If we failed to set the composition text, then we need to let the browser
751 // process to cancel the input method's ongoing composition session, to make
752 // sure we are in a consistent state.
753 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:26754 }
[email protected]fa7b1dc2010-06-23 17:53:04755}
756
757void RenderWidget::OnImeConfirmComposition() {
758 if (webwidget_)
759 webwidget_->confirmComposition();
initial.commit09911bf2008-07-26 23:55:29760}
761
[email protected]948f7ab72010-05-28 23:48:08762// This message causes the renderer to render an image of the
763// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:49764void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:09765 int tag,
[email protected]948f7ab72010-05-28 23:48:08766 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:49767 const gfx::Size& desired_size) {
768 if (!webwidget_ || dib_handle == TransportDIB::DefaultHandleValue())
769 return;
770
[email protected]948f7ab72010-05-28 23:48:08771 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:49772 // If one of these is empty, then we just return the dib we were
773 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:09774 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:49775 return;
776 }
777
778 // Map the given DIB ID into this process, and unmap it at the end
779 // of this function.
[email protected]948f7ab72010-05-28 23:48:08780 scoped_ptr<TransportDIB> paint_at_size_buffer(TransportDIB::Map(dib_handle));
[email protected]d65adb12010-04-28 17:26:49781
[email protected]948f7ab72010-05-28 23:48:08782 DCHECK(paint_at_size_buffer.get());
783 if (!paint_at_size_buffer.get())
[email protected]d65adb12010-04-28 17:26:49784 return;
785
[email protected]948f7ab72010-05-28 23:48:08786 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:49787 float x_scale = static_cast<float>(desired_size.width()) /
788 static_cast<float>(canvas_size.width());
789 float y_scale = static_cast<float>(desired_size.height()) /
790 static_cast<float>(canvas_size.height());
791
[email protected]ee8d6fd2010-05-26 17:05:48792 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:49793 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
794 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:48795 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:49796
797 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]948f7ab72010-05-28 23:48:08798 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
799 canvas_size.height()));
[email protected]d65adb12010-04-28 17:26:49800 if (!canvas.get()) {
801 NOTREACHED();
802 return;
803 }
804
805 // Reset bounds to what we actually received, but they should be the
806 // same.
807 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
808 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
809 bounds.set_width(canvas->getDevice()->width());
810 bounds.set_height(canvas->getDevice()->height());
811
812 canvas->save();
[email protected]948f7ab72010-05-28 23:48:08813 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:49814 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
815
[email protected]948f7ab72010-05-28 23:48:08816 // Have to make sure we're laid out at the right size before
817 // rendering.
818 gfx::Size old_size = webwidget_->size();
819 webwidget_->resize(page_size);
820 webwidget_->layout();
821
[email protected]d65adb12010-04-28 17:26:49822 // Paint the entire thing (using original bounds, not scaled bounds).
823 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
824 canvas->restore();
825
[email protected]948f7ab72010-05-28 23:48:08826 // Return the widget to its previous size.
827 webwidget_->resize(old_size);
828
[email protected]c88c9442010-07-19 18:55:09829 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:49830}
831
[email protected]ec7dc112008-08-06 05:30:12832void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
833 // During shutdown we can just ignore this message.
834 if (!webwidget_)
835 return;
836
837 set_next_paint_is_repaint_ack();
838 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
[email protected]4873c7d2009-07-16 06:36:28839 didInvalidateRect(repaint_rect);
[email protected]ec7dc112008-08-06 05:30:12840}
841
[email protected]4873c7d2009-07-16 06:36:28842void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:11843 if (!webwidget_)
844 return;
[email protected]4873c7d2009-07-16 06:36:28845 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:11846}
847
[email protected]bee16aab2009-08-26 15:55:03848void RenderWidget::SetHidden(bool hidden) {
849 if (is_hidden_ == hidden)
850 return;
851
852 // The status has changed. Tell the RenderThread about it.
853 is_hidden_ = hidden;
854 if (is_hidden_)
855 render_thread_->WidgetHidden();
856 else
857 render_thread_->WidgetRestored();
858}
859
[email protected]699ab0d2009-04-23 23:19:14860void RenderWidget::SetBackground(const SkBitmap& background) {
861 background_ = background;
862 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:28863 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:14864}
865
[email protected]674741932009-02-04 23:44:46866bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:05867 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:46868}
869
870bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:05871 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:46872}
873
874void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:05875 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:46876}
877
878void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:05879 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:46880}
881
882void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:05883 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:46884}
885
[email protected]fa7b1dc2010-06-23 17:53:04886void RenderWidget::UpdateInputMethod() {
887 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:29888 return;
[email protected]fa7b1dc2010-06-23 17:53:04889
890 WebTextInputType new_type = WebKit::WebTextInputTypeNone;
891 WebRect new_caret_bounds;
892
893 if (webwidget_) {
894 new_type = webwidget_->textInputType();
895 new_caret_bounds = webwidget_->caretOrSelectionBounds();
initial.commit09911bf2008-07-26 23:55:29896 }
[email protected]fa7b1dc2010-06-23 17:53:04897
898 // Only sends text input type and caret bounds to the browser process if they
899 // are changed.
900 if (text_input_type_ != new_type || caret_bounds_ != new_caret_bounds) {
901 text_input_type_ = new_type;
902 caret_bounds_ = new_caret_bounds;
903 Send(new ViewHostMsg_ImeUpdateTextInputState(
904 routing_id(), new_type, new_caret_bounds));
initial.commit09911bf2008-07-26 23:55:29905 }
initial.commit09911bf2008-07-26 23:55:29906}
907
[email protected]4873c7d2009-07-16 06:36:28908WebScreenInfo RenderWidget::screenInfo() {
909 WebScreenInfo results;
910 Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results));
911 return results;
912}
913
[email protected]fa7b1dc2010-06-23 17:53:04914void RenderWidget::resetInputMethod() {
915 if (!input_method_is_active_)
916 return;
917
918 // If the last text input type is not None, then we should finish any
919 // ongoing composition regardless of the new text input type.
920 if (text_input_type_ != WebKit::WebTextInputTypeNone) {
921 // If a composition text exists, then we need to let the browser process
922 // to cancel the input method's ongoing composition session.
923 if (webwidget_->confirmComposition())
924 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
925 }
926}
927
[email protected]f103ab72009-09-02 17:10:59928void RenderWidget::SchedulePluginMove(
929 const webkit_glue::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:29930 size_t i = 0;
931 for (; i < plugin_window_moves_.size(); ++i) {
932 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:58933 if (move.rects_valid) {
934 plugin_window_moves_[i] = move;
935 } else {
936 plugin_window_moves_[i].visible = move.visible;
937 }
initial.commit09911bf2008-07-26 23:55:29938 break;
939 }
940 }
941
942 if (i == plugin_window_moves_.size())
943 plugin_window_moves_.push_back(move);
944}
[email protected]268654772009-08-06 23:02:04945
946void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
947 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
948 i != plugin_window_moves_.end(); ++i) {
949 if (i->window == window) {
950 plugin_window_moves_.erase(i);
951 break;
952 }
953 }
954}