blob: 7b14ccdcb09af928193f17f2b63babe149755a44 [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]8085dbc82008-09-26 22:53:4416#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2817#include "chrome/renderer/render_thread.h"
[email protected]e0fc2f12010-03-14 23:30:5918#include "gfx/point.h"
19#include "gfx/size.h"
[email protected]484955942010-08-19 16:13:1820#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4821#include "skia/ext/platform_canvas.h"
[email protected]d5282e72009-05-13 13:16:5222#include "third_party/skia/include/core/SkShader.h"
[email protected]418ed5ab2009-11-12 01:14:4923#include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h"
24#include "third_party/WebKit/WebKit/chromium/public/WebPopupMenu.h"
25#include "third_party/WebKit/WebKit/chromium/public/WebPopupMenuInfo.h"
26#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
27#include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h"
28#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]7a4de7a62010-08-17 18:38:2429#include "webkit/glue/plugins/webplugin.h"
[email protected]8c89e7792009-08-19 21:18:3430#include "webkit/glue/webkit_glue.h"
[email protected]661eb9d2009-02-03 02:11:4831
32#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4933#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5234#include "third_party/skia/include/core/SkPixelRef.h"
35#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4836#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4437
[email protected]418ed5ab2009-11-12 01:14:4938#include "third_party/WebKit/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2939
[email protected]fa7b1dc2010-06-23 17:53:0440using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3041using WebKit::WebCursorInfo;
[email protected]62cb33cae2009-03-27 23:30:2242using WebKit::WebInputEvent;
[email protected]4873c7d2009-07-16 06:36:2843using WebKit::WebNavigationPolicy;
44using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5945using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1846using WebKit::WebPopupType;
[email protected]b3f2b912009-04-09 16:18:5247using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1948using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5249using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2850using WebKit::WebTextDirection;
[email protected]fa7b1dc2010-06-23 17:53:0451using WebKit::WebTextInputType;
52using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1853using WebKit::WebWidget;
[email protected]62cb33cae2009-03-27 23:30:2254
[email protected]3e2b375b2010-04-07 17:03:1255RenderWidget::RenderWidget(RenderThreadBase* render_thread,
56 WebKit::WebPopupType popup_type)
initial.commit09911bf2008-07-26 23:55:2957 : routing_id_(MSG_ROUTING_NONE),
[email protected]c5b3b5e2009-02-13 06:41:1158 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2959 opener_id_(MSG_ROUTING_NONE),
[email protected]8085dbc82008-09-26 22:53:4460 render_thread_(render_thread),
[email protected]659f73f2009-10-13 13:43:4261 host_window_(0),
initial.commit09911bf2008-07-26 23:55:2962 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2963 next_paint_flags_(0),
[email protected]53d3f302009-12-21 04:42:0564 update_reply_pending_(false),
initial.commit09911bf2008-07-26 23:55:2965 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2966 is_hidden_(false),
67 needs_repainting_on_restore_(false),
68 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4969 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4870 closing_(false),
[email protected]fa7b1dc2010-06-23 17:53:0471 input_method_is_active_(false),
72 text_input_type_(WebKit::WebTextInputTypeNone),
[email protected]3e2b375b2010-04-07 17:03:1273 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:4874 pending_window_rect_count_(0),
[email protected]edbcde932010-05-07 17:10:4675 suppress_next_char_events_(false),
76 is_gpu_rendering_active_(false) {
[email protected]8930d472009-02-21 08:05:2877 RenderProcess::current()->AddRefProcess();
[email protected]8085dbc82008-09-26 22:53:4478 DCHECK(render_thread_);
initial.commit09911bf2008-07-26 23:55:2979}
80
81RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:1182 DCHECK(!webwidget_) << "Leaking our WebWidget!";
initial.commit09911bf2008-07-26 23:55:2983 if (current_paint_buf_) {
[email protected]8930d472009-02-21 08:05:2884 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
initial.commit09911bf2008-07-26 23:55:2985 current_paint_buf_ = NULL;
86 }
[email protected]8930d472009-02-21 08:05:2887 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:2988}
89
[email protected]484955942010-08-19 16:13:1890// static
[email protected]8085dbc82008-09-26 22:53:4491RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]0ebf3872008-11-07 21:35:0392 RenderThreadBase* render_thread,
[email protected]3e2b375b2010-04-07 17:03:1293 WebKit::WebPopupType popup_type) {
initial.commit09911bf2008-07-26 23:55:2994 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]0ebf3872008-11-07 21:35:0395 scoped_refptr<RenderWidget> widget = new RenderWidget(render_thread,
[email protected]3e2b375b2010-04-07 17:03:1296 popup_type);
initial.commit09911bf2008-07-26 23:55:2997 widget->Init(opener_id); // adds reference
98 return widget;
99}
100
[email protected]484955942010-08-19 16:13:18101// static
102WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
103 switch (render_widget->popup_type_) {
104 case WebKit::WebPopupTypeNone: // Nothing to create.
105 break;
106 case WebKit::WebPopupTypeSelect:
107 case WebKit::WebPopupTypeSuggestion:
108 return WebPopupMenu::create(render_widget);
109 default:
110 NOTREACHED();
111 }
112 return NULL;
113}
114
[email protected]88efb7ec2009-07-14 16:32:59115void RenderWidget::ConfigureAsExternalPopupMenu(const WebPopupMenuInfo& info) {
116 popup_params_.reset(new ViewHostMsg_ShowPopup_Params);
117 popup_params_->item_height = info.itemHeight;
[email protected]c9e19792010-03-17 17:02:59118 popup_params_->item_font_size = info.itemFontSize;
[email protected]88efb7ec2009-07-14 16:32:59119 popup_params_->selected_item = info.selectedIndex;
120 for (size_t i = 0; i < info.items.size(); ++i)
121 popup_params_->popup_items.push_back(WebMenuItem(info.items[i]));
[email protected]b88ab032010-05-13 22:13:04122 popup_params_->right_aligned = info.rightAligned;
[email protected]88efb7ec2009-07-14 16:32:59123}
124
initial.commit09911bf2008-07-26 23:55:29125void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18126 DoInit(opener_id,
127 RenderWidget::CreateWebWidget(this),
128 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
129}
130
131
132void RenderWidget::DoInit(int32 opener_id,
133 WebKit::WebWidget* web_widget,
134 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29135 DCHECK(!webwidget_);
136
137 if (opener_id != MSG_ROUTING_NONE)
138 opener_id_ = opener_id;
139
[email protected]484955942010-08-19 16:13:18140 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29141
[email protected]484955942010-08-19 16:13:18142 bool result = render_thread_->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29143 if (result) {
[email protected]8085dbc82008-09-26 22:53:44144 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29145 // Take a reference on behalf of the RenderThread. This will be balanced
146 // when we receive ViewMsg_Close.
147 AddRef();
148 } else {
149 DCHECK(false);
150 }
151}
152
153// This is used to complete pending inits and non-pending inits. For non-
154// pending cases, the parent will be the same as the current parent. This
155// indicates we do not need to reparent or anything.
[email protected]18bcc3c2009-01-27 21:39:15156void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29157 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29158
159 host_window_ = parent_hwnd;
160
[email protected]6de74452009-02-25 18:04:59161 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29162}
163
164IPC_DEFINE_MESSAGE_MAP(RenderWidget)
165 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
166 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
167 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
168 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
169 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]53d3f302009-12-21 04:42:05170 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]8400e032010-02-26 18:50:11171 IPC_MESSAGE_HANDLER(ViewMsg_CreateVideo_ACK, OnCreateVideoAck)
172 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVideo_ACK, OnUpdateVideoAck)
initial.commit09911bf2008-07-26 23:55:29173 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
174 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
175 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
[email protected]fa7b1dc2010-06-23 17:53:04176 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
initial.commit09911bf2008-07-26 23:55:29177 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
[email protected]fa7b1dc2010-06-23 17:53:04178 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]d65adb12010-04-28 17:26:49179 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
[email protected]ec7dc112008-08-06 05:30:12180 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
[email protected]07f953332009-03-25 04:31:11181 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
[email protected]2533ce12009-05-09 00:02:24182 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
initial.commit09911bf2008-07-26 23:55:29183 IPC_MESSAGE_UNHANDLED_ERROR()
184IPC_END_MESSAGE_MAP()
185
186bool RenderWidget::Send(IPC::Message* message) {
187 // Don't send any messages after the browser has told us to close.
188 if (closing_) {
189 delete message;
190 return false;
191 }
192
193 // If given a messsage without a routing ID, then assign our routing ID.
194 if (message->routing_id() == MSG_ROUTING_NONE)
195 message->set_routing_id(routing_id_);
196
[email protected]d3fc25652009-02-24 22:31:25197 return render_thread_->Send(message);
[email protected]8085dbc82008-09-26 22:53:44198}
199
initial.commit09911bf2008-07-26 23:55:29200// Got a response from the browser after the renderer decided to create a new
201// view.
[email protected]18bcc3c2009-01-27 21:39:15202void RenderWidget::OnCreatingNewAck(gfx::NativeViewId parent) {
initial.commit09911bf2008-07-26 23:55:29203 DCHECK(routing_id_ != MSG_ROUTING_NONE);
204
205 CompleteInit(parent);
206}
207
208void RenderWidget::OnClose() {
209 if (closing_)
210 return;
211 closing_ = true;
212
213 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03214 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]8085dbc82008-09-26 22:53:44215 render_thread_->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03216 SetHidden(false);
217 }
initial.commit09911bf2008-07-26 23:55:29218
initial.commit09911bf2008-07-26 23:55:29219 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25220 // now. Post a task that only gets invoked when there are no nested message
221 // loops.
222 MessageLoop::current()->PostNonNestableTask(FROM_HERE,
223 NewRunnableMethod(this, &RenderWidget::Close));
224
225 // Balances the AddRef taken when we called AddRoute.
226 Release();
initial.commit09911bf2008-07-26 23:55:29227}
228
[email protected]f21c613a2009-02-12 14:46:17229void RenderWidget::OnResize(const gfx::Size& new_size,
230 const gfx::Rect& resizer_rect) {
initial.commit09911bf2008-07-26 23:55:29231 // During shutdown we can just ignore this message.
232 if (!webwidget_)
233 return;
234
[email protected]f21c613a2009-02-12 14:46:17235 // Remember the rect where the resize corner will be drawn.
236 resizer_rect_ = resizer_rect;
237
initial.commit09911bf2008-07-26 23:55:29238 // TODO(darin): We should not need to reset this here.
[email protected]bee16aab2009-08-26 15:55:03239 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29240 needs_repainting_on_restore_ = false;
241
242 // We shouldn't be asked to resize to our current size.
243 DCHECK(size_ != new_size);
244 size_ = new_size;
245
246 // We should not be sent a Resize message if we have not ACK'd the previous
247 DCHECK(!next_paint_is_resize_ack());
248
[email protected]552e6002009-11-19 05:24:57249 paint_aggregator_.ClearPendingUpdate();
250
initial.commit09911bf2008-07-26 23:55:29251 // When resizing, we want to wait to paint before ACK'ing the resize. This
252 // ensures that we only resize as fast as we can paint. We only need to send
253 // an ACK if we are resized to a non-empty rect.
[email protected]4873c7d2009-07-16 06:36:28254 webwidget_->resize(new_size);
initial.commit09911bf2008-07-26 23:55:29255 if (!new_size.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57256 // Resize should have caused an invalidation of the entire view.
257 DCHECK(paint_aggregator_.HasPendingUpdate());
[email protected]2d5d09d52009-06-15 14:29:21258
initial.commit09911bf2008-07-26 23:55:29259 // We will send the Resize_ACK flag once we paint again.
260 set_next_paint_is_resize_ack();
261 }
262}
263
264void RenderWidget::OnWasHidden() {
265 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03266 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29267}
268
269void RenderWidget::OnWasRestored(bool needs_repainting) {
270 // During shutdown we can just ignore this message.
271 if (!webwidget_)
272 return;
273
274 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03275 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29276
277 if (!needs_repainting && !needs_repainting_on_restore_)
278 return;
279 needs_repainting_on_restore_ = false;
280
[email protected]d65adb12010-04-28 17:26:49281 // Tag the next paint as a restore ack, which is picked up by
282 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29283 set_next_paint_is_restore_ack();
284
285 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:28286 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
initial.commit09911bf2008-07-26 23:55:29287}
288
[email protected]53d3f302009-12-21 04:42:05289void RenderWidget::OnRequestMoveAck() {
290 DCHECK(pending_window_rect_count_);
291 pending_window_rect_count_--;
292}
293
294void RenderWidget::OnUpdateRectAck() {
295 DCHECK(update_reply_pending());
296 update_reply_pending_ = false;
297
298 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
[email protected]d65adb12010-04-28 17:26:49299 // have no current paint buffer.
[email protected]b7fce1f2008-08-14 05:01:07300 if (current_paint_buf_) {
[email protected]8930d472009-02-21 08:05:28301 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
[email protected]b7fce1f2008-08-14 05:01:07302 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29303 }
[email protected]e68e62fa2009-02-20 02:00:04304
[email protected]00c39612010-03-06 02:53:28305 // Notify subclasses.
306 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25307
initial.commit09911bf2008-07-26 23:55:29308 // Continue painting if necessary...
[email protected]552e6002009-11-19 05:24:57309 CallDoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29310}
311
[email protected]8400e032010-02-26 18:50:11312void RenderWidget::OnCreateVideoAck(int32 video_id) {
313 // TODO(scherkus): handle CreateVideo_ACK with a message filter.
314}
315
316void RenderWidget::OnUpdateVideoAck(int32 video_id) {
317 // TODO(scherkus): handle UpdateVideo_ACK with a message filter.
318}
319
initial.commit09911bf2008-07-26 23:55:29320void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
321 void* iter = NULL;
322
323 const char* data;
324 int data_length;
[email protected]5dd768212009-08-13 23:34:49325 handling_input_event_ = true;
326 if (!message.ReadData(&iter, &data, &data_length)) {
327 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29328 return;
[email protected]5dd768212009-08-13 23:34:49329 }
initial.commit09911bf2008-07-26 23:55:29330
331 const WebInputEvent* input_event =
332 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48333
334 bool is_keyboard_shortcut = false;
335 // is_keyboard_shortcut flag is only available for RawKeyDown events.
336 if (input_event->type == WebInputEvent::RawKeyDown)
337 message.ReadBool(&iter, &is_keyboard_shortcut);
338
initial.commit09911bf2008-07-26 23:55:29339 bool processed = false;
[email protected]867125a02009-12-10 06:01:48340 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
341 suppress_next_char_events_ = false;
342 if (webwidget_)
343 processed = webwidget_->handleInputEvent(*input_event);
344 }
345
346 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
347 // it's not processed by webkit, then we need to suppress the upcoming Char
348 // events.
349 if (!processed && is_keyboard_shortcut)
350 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29351
352 IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_);
353 response->WriteInt(input_event->type);
[email protected]e2824412009-02-27 01:57:05354 response->WriteBool(processed);
355
[email protected]353a34c2010-05-28 23:35:17356 if ((input_event->type == WebInputEvent::MouseMove ||
357 input_event->type == WebInputEvent::MouseWheel) &&
[email protected]552e6002009-11-19 05:24:57358 paint_aggregator_.HasPendingUpdate()) {
[email protected]12fbad812009-09-01 18:21:24359 // We want to rate limit the input events in this case, so we'll wait for
360 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17361 if (pending_input_event_ack_.get()) {
362 // As two different kinds of events could cause us to postpone an ack
363 // we send it now, if we have one pending. The Browser should never
364 // send us the same kind of event we are delaying the ack for.
365 Send(pending_input_event_ack_.release());
366 }
[email protected]12fbad812009-09-01 18:21:24367 pending_input_event_ack_.reset(response);
368 } else {
369 Send(response);
370 }
371
[email protected]5dd768212009-08-13 23:34:49372 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48373
[email protected]867125a02009-12-10 06:01:48374 if (WebInputEvent::isKeyboardEventType(input_event->type))
[email protected]446705872009-09-10 07:22:48375 DidHandleKeyEvent();
initial.commit09911bf2008-07-26 23:55:29376}
377
378void RenderWidget::OnMouseCaptureLost() {
379 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28380 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29381}
382
383void RenderWidget::OnSetFocus(bool enable) {
384 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33385 if (webwidget_)
386 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29387}
388
389void RenderWidget::ClearFocus() {
390 // We may have got the focus from the browser before this gets processed, in
391 // which case we do not want to unfocus ourself.
392 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28393 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29394}
395
[email protected]2d5d09d52009-06-15 14:29:21396void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00397 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21398 skia::PlatformCanvas* canvas) {
[email protected]4fb66842009-12-04 21:41:00399 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21400
401 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00402 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
403 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03404
[email protected]699ab0d2009-04-23 23:19:14405 // If there is a custom background, tile it.
406 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14407 SkPaint paint;
408 SkShader* shader = SkShader::CreateBitmapShader(background_,
409 SkShader::kRepeat_TileMode,
410 SkShader::kRepeat_TileMode);
411 paint.setShader(shader)->unref();
[email protected]8860e4f52009-06-25 01:01:52412 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
[email protected]699ab0d2009-04-23 23:19:14413 canvas->drawPaint(paint);
[email protected]699ab0d2009-04-23 23:19:14414 }
415
[email protected]01b47232010-07-01 20:33:47416 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
initial.commit09911bf2008-07-26 23:55:29417
[email protected]4fb66842009-12-04 21:41:00418 PaintDebugBorder(rect, canvas);
419
initial.commit09911bf2008-07-26 23:55:29420 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]661eb9d2009-02-03 02:11:48421 canvas->getTopPlatformDevice().accessBitmap(false);
[email protected]4fb66842009-12-04 21:41:00422
423 canvas->restore();
424}
425
426void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
427 skia::PlatformCanvas* canvas) {
428 static bool kPaintBorder =
429 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
430 if (!kPaintBorder)
431 return;
432
[email protected]53d3f302009-12-21 04:42:05433 // Cycle through these colors to help distinguish new paint rects.
434 const SkColor colors[] = {
435 SkColorSetARGB(0x3F, 0xFF, 0, 0),
436 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
437 SkColorSetARGB(0x3F, 0, 0, 0xFF),
438 };
439 static int color_selector = 0;
440
[email protected]4fb66842009-12-04 21:41:00441 SkPaint paint;
442 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05443 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00444 paint.setStrokeWidth(1);
445
446 SkIRect irect;
447 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
448 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29449}
450
[email protected]552e6002009-11-19 05:24:57451void RenderWidget::CallDoDeferredUpdate() {
452 DoDeferredUpdate();
[email protected]12fbad812009-09-01 18:21:24453
[email protected]d22d8732010-05-04 19:24:42454 if (pending_input_event_ack_.get())
455 Send(pending_input_event_ack_.release());
[email protected]12fbad812009-09-01 18:21:24456}
457
[email protected]552e6002009-11-19 05:24:57458void RenderWidget::DoDeferredUpdate() {
459 if (!webwidget_ || !paint_aggregator_.HasPendingUpdate() ||
[email protected]53d3f302009-12-21 04:42:05460 update_reply_pending())
initial.commit09911bf2008-07-26 23:55:29461 return;
462
[email protected]552e6002009-11-19 05:24:57463 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29464 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57465 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29466 needs_repainting_on_restore_ = true;
467 return;
468 }
469
[email protected]edbcde932010-05-07 17:10:46470 // If we are using accelerated compositing then all the drawing
471 // to the associated window happens directly from the gpu process and the
472 // browser process shouldn't do any drawing.
473 // TODO(vangelis): Currently the accelerated compositing path relies on
474 // invalidating parts of the page so that we get a request to redraw.
475 // This needs to change to a model where the compositor updates the
476 // contents of the page independently and the browser process gets no
477 // longer involved.
478 if (webwidget_->isAcceleratedCompositingActive() !=
479 is_gpu_rendering_active_) {
480 is_gpu_rendering_active_ = webwidget_->isAcceleratedCompositingActive();
481 Send(new ViewHostMsg_GpuRenderingActivated(
482 routing_id_, is_gpu_rendering_active_));
483 }
484
[email protected]552e6002009-11-19 05:24:57485 // Layout may generate more invalidation.
[email protected]4873c7d2009-07-16 06:36:28486 webwidget_->layout();
initial.commit09911bf2008-07-26 23:55:29487
[email protected]552e6002009-11-19 05:24:57488 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29489 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]552e6002009-11-19 05:24:57490 PaintAggregator::PendingUpdate update = paint_aggregator_.GetPendingUpdate();
491 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29492
[email protected]53d3f302009-12-21 04:42:05493 gfx::Rect scroll_damage = update.GetScrollDamage();
494 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29495
[email protected]53d3f302009-12-21 04:42:05496 // Compute a buffer for painting and cache it.
497 scoped_ptr<skia::PlatformCanvas> canvas(
498 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_, bounds));
499 if (!canvas.get()) {
500 NOTREACHED();
501 return;
[email protected]552e6002009-11-19 05:24:57502 }
503
[email protected]53d3f302009-12-21 04:42:05504 // We may get back a smaller canvas than we asked for.
505 // TODO(darin): This seems like it could cause painting problems!
506 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
507 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
508 bounds.set_width(canvas->getDevice()->width());
509 bounds.set_height(canvas->getDevice()->height());
[email protected]552e6002009-11-19 05:24:57510
[email protected]53d3f302009-12-21 04:42:05511 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
[email protected]552e6002009-11-19 05:24:57512
[email protected]53d3f302009-12-21 04:42:05513 // TODO(darin): Re-enable painting multiple damage rects once the
514 // page-cycler regressions are resolved. See bug 29589.
515 if (update.scroll_rect.IsEmpty()) {
516 update.paint_rects.clear();
517 update.paint_rects.push_back(bounds);
initial.commit09911bf2008-07-26 23:55:29518 }
519
[email protected]cef3362f2009-12-21 17:48:45520 // The scroll damage is just another rectangle to paint and copy.
521 std::vector<gfx::Rect> copy_rects;
522 copy_rects.swap(update.paint_rects);
523 if (!scroll_damage.IsEmpty())
524 copy_rects.push_back(scroll_damage);
525
[email protected]53d3f302009-12-21 04:42:05526 for (size_t i = 0; i < copy_rects.size(); ++i)
527 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
528
529 ViewHostMsg_UpdateRect_Params params;
530 params.bitmap = current_paint_buf_->id();
531 params.bitmap_rect = bounds;
532 params.dx = update.scroll_delta.x();
533 params.dy = update.scroll_delta.y();
[email protected]b167ca662010-05-14 00:05:34534 if (is_gpu_rendering_active_) {
535 // If painting is done via the gpu process then we clear out all damage
536 // rects to save the browser process from doing unecessary work.
537 params.scroll_rect = gfx::Rect();
538 params.copy_rects.clear();
539 } else {
540 params.scroll_rect = update.scroll_rect;
541 params.copy_rects.swap(copy_rects); // TODO(darin): clip to bounds?
542 }
[email protected]53d3f302009-12-21 04:42:05543 params.view_size = size_;
544 params.plugin_window_moves.swap(plugin_window_moves_);
545 params.flags = next_paint_flags_;
546
547 update_reply_pending_ = true;
548 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
549 next_paint_flags_ = 0;
550
[email protected]fa7b1dc2010-06-23 17:53:04551 UpdateInputMethod();
[email protected]00c39612010-03-06 02:53:28552
553 // Let derived classes know we've painted.
554 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:29555}
556
557///////////////////////////////////////////////////////////////////////////////
558// WebWidgetDelegate
559
[email protected]4873c7d2009-07-16 06:36:28560void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:57561 // We only want one pending DoDeferredUpdate call at any time...
562 bool update_pending = paint_aggregator_.HasPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29563
[email protected]552e6002009-11-19 05:24:57564 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48565 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57566 gfx::Rect damaged_rect = view_rect.Intersect(rect);
567 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29568 return;
569
[email protected]552e6002009-11-19 05:24:57570 paint_aggregator_.InvalidateRect(damaged_rect);
571
572 // We may not need to schedule another call to DoDeferredUpdate.
573 if (update_pending)
574 return;
575 if (!paint_aggregator_.HasPendingUpdate())
576 return;
[email protected]53d3f302009-12-21 04:42:05577 if (update_reply_pending())
[email protected]552e6002009-11-19 05:24:57578 return;
579
580 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:29581 // 1) Ensures that we call WebView::Paint without a bunch of other junk
582 // on the call stack.
583 // 2) Allows us to collect more damage rects before painting to help coalesce
584 // the work that we will need to do.
585 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]552e6002009-11-19 05:24:57586 this, &RenderWidget::CallDoDeferredUpdate));
initial.commit09911bf2008-07-26 23:55:29587}
588
[email protected]4873c7d2009-07-16 06:36:28589void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]552e6002009-11-19 05:24:57590 // We only want one pending DoDeferredUpdate call at any time...
591 bool update_pending = paint_aggregator_.HasPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29592
[email protected]552e6002009-11-19 05:24:57593 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48594 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57595 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
596 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29597 return;
598
[email protected]552e6002009-11-19 05:24:57599 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
600
601 // We may not need to schedule another call to DoDeferredUpdate.
602 if (update_pending)
603 return;
604 if (!paint_aggregator_.HasPendingUpdate())
605 return;
[email protected]53d3f302009-12-21 04:42:05606 if (update_reply_pending())
[email protected]552e6002009-11-19 05:24:57607 return;
608
609 // Perform updating asynchronously. This serves two purposes:
610 // 1) Ensures that we call WebView::Paint without a bunch of other junk
611 // on the call stack.
612 // 2) Allows us to collect more damage rects before painting to help coalesce
613 // the work that we will need to do.
initial.commit09911bf2008-07-26 23:55:29614 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]552e6002009-11-19 05:24:57615 this, &RenderWidget::CallDoDeferredUpdate));
initial.commit09911bf2008-07-26 23:55:29616}
617
[email protected]4873c7d2009-07-16 06:36:28618void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:30619 // TODO(darin): Eliminate this temporary.
620 WebCursor cursor(cursor_info);
621
initial.commit09911bf2008-07-26 23:55:29622 // Only send a SetCursor message if we need to make a change.
623 if (!current_cursor_.IsEqual(cursor)) {
624 current_cursor_ = cursor;
625 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
626 }
627}
628
629// We are supposed to get a single call to Show for a newly created RenderWidget
630// that was created via RenderWidget::CreateWebView. So, we wait until this
631// point to dispatch the ShowWidget message.
632//
633// This method provides us with the information about how to display the newly
634// created RenderWidget (i.e., as a constrained popup or as a new tab).
635//
[email protected]4873c7d2009-07-16 06:36:28636void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:29637 DCHECK(!did_show_) << "received extraneous Show call";
638 DCHECK(routing_id_ != MSG_ROUTING_NONE);
639 DCHECK(opener_id_ != MSG_ROUTING_NONE);
640
641 if (!did_show_) {
642 did_show_ = true;
643 // NOTE: initial_pos_ may still have its default values at this point, but
644 // that's okay. It'll be ignored if as_popup is false, or the browser
645 // process will impose a default position otherwise.
[email protected]88efb7ec2009-07-14 16:32:59646 if (popup_params_.get()) {
647 popup_params_->bounds = initial_pos_;
648 Send(new ViewHostMsg_ShowPopup(routing_id_, *popup_params_));
649 popup_params_.reset();
650 } else {
651 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
652 }
[email protected]2533ce12009-05-09 00:02:24653 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:29654 }
655}
656
[email protected]4873c7d2009-07-16 06:36:28657void RenderWidget::didFocus() {
[email protected]494f5c42010-08-11 06:44:38658 Send(new ViewHostMsg_Focus(routing_id_));
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 Send(new ViewHostMsg_Blur(routing_id_));
663}
664
[email protected]2533ce12009-05-09 00:02:24665void RenderWidget::DoDeferredClose() {
666 Send(new ViewHostMsg_Close(routing_id_));
667}
668
[email protected]4873c7d2009-07-16 06:36:28669void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:29670 // If a page calls window.close() twice, we'll end up here twice, but that's
671 // OK. It is safe to send multiple Close messages.
672
[email protected]2533ce12009-05-09 00:02:24673 // Ask the RenderWidgetHost to initiate close. We could be called from deep
674 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
675 // could be closed before the JS finishes executing. So instead, post a
676 // message back to the message loop, which won't run until the JS is
677 // complete, and then the Close message can be sent.
[email protected]75ae4492009-07-10 00:05:15678 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]2533ce12009-05-09 00:02:24679 this, &RenderWidget::DoDeferredClose));
initial.commit09911bf2008-07-26 23:55:29680}
681
[email protected]b4b967e2009-04-22 11:33:05682void RenderWidget::GenerateFullRepaint() {
[email protected]4873c7d2009-07-16 06:36:28683 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]b4b967e2009-04-22 11:33:05684}
685
initial.commit09911bf2008-07-26 23:55:29686void RenderWidget::Close() {
687 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:28688 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:29689 webwidget_ = NULL;
690 }
691}
692
[email protected]4873c7d2009-07-16 06:36:28693WebRect RenderWidget::windowRect() {
694 if (pending_window_rect_count_)
695 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:24696
[email protected]b3f2b912009-04-09 16:18:52697 gfx::Rect rect;
698 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:28699 return rect;
initial.commit09911bf2008-07-26 23:55:29700}
701
[email protected]4873c7d2009-07-16 06:36:28702void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:29703 if (did_show_) {
704 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:24705 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:29706 } else {
707 initial_pos_ = pos;
708 }
709}
710
[email protected]2533ce12009-05-09 00:02:24711void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
712 pending_window_rect_ = rect;
713 pending_window_rect_count_++;
714}
715
[email protected]4873c7d2009-07-16 06:36:28716WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:24717 if (pending_window_rect_count_) {
718 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
719 // the RootWindowRect is probably going to return wrong results since the
720 // browser may not have processed the Move yet. There isn't really anything
721 // good to do in this case, and it shouldn't happen - since this size is
722 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:28723 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:24724 }
725
[email protected]b3f2b912009-04-09 16:18:52726 gfx::Rect rect;
727 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:28728 return rect;
[email protected]d4547452008-08-28 18:36:37729}
730
[email protected]4873c7d2009-07-16 06:36:28731WebRect RenderWidget::windowResizerRect() {
732 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:19733}
734
[email protected]fa7b1dc2010-06-23 17:53:04735void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:03736 // To prevent this renderer process from sending unnecessary IPC messages to
737 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:04738 // only during the input method attached to the browser process is active.
739 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:29740}
741
[email protected]fa7b1dc2010-06-23 17:53:04742void RenderWidget::OnImeSetComposition(
743 const string16& text,
744 const std::vector<WebCompositionUnderline>& underlines,
745 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:28746 if (!webwidget_)
747 return;
[email protected]fa7b1dc2010-06-23 17:53:04748 if (!webwidget_->setComposition(
749 text, WebVector<WebCompositionUnderline>(underlines),
750 selection_start, selection_end)) {
751 // If we failed to set the composition text, then we need to let the browser
752 // process to cancel the input method's ongoing composition session, to make
753 // sure we are in a consistent state.
754 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:26755 }
[email protected]fa7b1dc2010-06-23 17:53:04756}
757
758void RenderWidget::OnImeConfirmComposition() {
759 if (webwidget_)
760 webwidget_->confirmComposition();
initial.commit09911bf2008-07-26 23:55:29761}
762
[email protected]948f7ab72010-05-28 23:48:08763// This message causes the renderer to render an image of the
764// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:49765void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:09766 int tag,
[email protected]948f7ab72010-05-28 23:48:08767 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:49768 const gfx::Size& desired_size) {
769 if (!webwidget_ || dib_handle == TransportDIB::DefaultHandleValue())
770 return;
771
[email protected]948f7ab72010-05-28 23:48:08772 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:49773 // If one of these is empty, then we just return the dib we were
774 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:09775 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:49776 return;
777 }
778
779 // Map the given DIB ID into this process, and unmap it at the end
780 // of this function.
[email protected]948f7ab72010-05-28 23:48:08781 scoped_ptr<TransportDIB> paint_at_size_buffer(TransportDIB::Map(dib_handle));
[email protected]d65adb12010-04-28 17:26:49782
[email protected]948f7ab72010-05-28 23:48:08783 DCHECK(paint_at_size_buffer.get());
784 if (!paint_at_size_buffer.get())
[email protected]d65adb12010-04-28 17:26:49785 return;
786
[email protected]948f7ab72010-05-28 23:48:08787 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:49788 float x_scale = static_cast<float>(desired_size.width()) /
789 static_cast<float>(canvas_size.width());
790 float y_scale = static_cast<float>(desired_size.height()) /
791 static_cast<float>(canvas_size.height());
792
[email protected]ee8d6fd2010-05-26 17:05:48793 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:49794 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
795 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:48796 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:49797
798 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]948f7ab72010-05-28 23:48:08799 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
800 canvas_size.height()));
[email protected]d65adb12010-04-28 17:26:49801 if (!canvas.get()) {
802 NOTREACHED();
803 return;
804 }
805
806 // Reset bounds to what we actually received, but they should be the
807 // same.
808 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
809 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
810 bounds.set_width(canvas->getDevice()->width());
811 bounds.set_height(canvas->getDevice()->height());
812
813 canvas->save();
[email protected]948f7ab72010-05-28 23:48:08814 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:49815 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
816
[email protected]948f7ab72010-05-28 23:48:08817 // Have to make sure we're laid out at the right size before
818 // rendering.
819 gfx::Size old_size = webwidget_->size();
820 webwidget_->resize(page_size);
821 webwidget_->layout();
822
[email protected]d65adb12010-04-28 17:26:49823 // Paint the entire thing (using original bounds, not scaled bounds).
824 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
825 canvas->restore();
826
[email protected]948f7ab72010-05-28 23:48:08827 // Return the widget to its previous size.
828 webwidget_->resize(old_size);
829
[email protected]c88c9442010-07-19 18:55:09830 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:49831}
832
[email protected]ec7dc112008-08-06 05:30:12833void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
834 // During shutdown we can just ignore this message.
835 if (!webwidget_)
836 return;
837
838 set_next_paint_is_repaint_ack();
839 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
[email protected]4873c7d2009-07-16 06:36:28840 didInvalidateRect(repaint_rect);
[email protected]ec7dc112008-08-06 05:30:12841}
842
[email protected]4873c7d2009-07-16 06:36:28843void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:11844 if (!webwidget_)
845 return;
[email protected]4873c7d2009-07-16 06:36:28846 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:11847}
848
[email protected]bee16aab2009-08-26 15:55:03849void RenderWidget::SetHidden(bool hidden) {
850 if (is_hidden_ == hidden)
851 return;
852
853 // The status has changed. Tell the RenderThread about it.
854 is_hidden_ = hidden;
855 if (is_hidden_)
856 render_thread_->WidgetHidden();
857 else
858 render_thread_->WidgetRestored();
859}
860
[email protected]699ab0d2009-04-23 23:19:14861void RenderWidget::SetBackground(const SkBitmap& background) {
862 background_ = background;
863 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:28864 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:14865}
866
[email protected]674741932009-02-04 23:44:46867bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:05868 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:46869}
870
871bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:05872 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:46873}
874
875void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:05876 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:46877}
878
879void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:05880 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:46881}
882
883void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:05884 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:46885}
886
[email protected]fa7b1dc2010-06-23 17:53:04887void RenderWidget::UpdateInputMethod() {
888 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:29889 return;
[email protected]fa7b1dc2010-06-23 17:53:04890
891 WebTextInputType new_type = WebKit::WebTextInputTypeNone;
892 WebRect new_caret_bounds;
893
894 if (webwidget_) {
895 new_type = webwidget_->textInputType();
896 new_caret_bounds = webwidget_->caretOrSelectionBounds();
initial.commit09911bf2008-07-26 23:55:29897 }
[email protected]fa7b1dc2010-06-23 17:53:04898
899 // Only sends text input type and caret bounds to the browser process if they
900 // are changed.
901 if (text_input_type_ != new_type || caret_bounds_ != new_caret_bounds) {
902 text_input_type_ = new_type;
903 caret_bounds_ = new_caret_bounds;
904 Send(new ViewHostMsg_ImeUpdateTextInputState(
905 routing_id(), new_type, new_caret_bounds));
initial.commit09911bf2008-07-26 23:55:29906 }
initial.commit09911bf2008-07-26 23:55:29907}
908
[email protected]4873c7d2009-07-16 06:36:28909WebScreenInfo RenderWidget::screenInfo() {
910 WebScreenInfo results;
911 Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results));
912 return results;
913}
914
[email protected]fa7b1dc2010-06-23 17:53:04915void RenderWidget::resetInputMethod() {
916 if (!input_method_is_active_)
917 return;
918
919 // If the last text input type is not None, then we should finish any
920 // ongoing composition regardless of the new text input type.
921 if (text_input_type_ != WebKit::WebTextInputTypeNone) {
922 // If a composition text exists, then we need to let the browser process
923 // to cancel the input method's ongoing composition session.
924 if (webwidget_->confirmComposition())
925 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
926 }
927}
928
[email protected]f103ab72009-09-02 17:10:59929void RenderWidget::SchedulePluginMove(
930 const webkit_glue::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:29931 size_t i = 0;
932 for (; i < plugin_window_moves_.size(); ++i) {
933 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:58934 if (move.rects_valid) {
935 plugin_window_moves_[i] = move;
936 } else {
937 plugin_window_moves_[i].visible = move.visible;
938 }
initial.commit09911bf2008-07-26 23:55:29939 break;
940 }
941 }
942
943 if (i == plugin_window_moves_.size())
944 plugin_window_moves_.push_back(move);
945}
[email protected]268654772009-08-06 23:02:04946
947void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
948 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
949 i != plugin_window_moves_.end(); ++i) {
950 if (i->window == window) {
951 plugin_window_moves_.erase(i);
952 break;
953 }
954 }
955}