OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "app/keyboard_code_conversion_gtk.h" | 10 #include "app/keyboard_code_conversion_gtk.h" |
11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
12 #include "app/x11_util.h" | 12 #include "app/x11_util.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
18 #include "base/task.h" | 18 #include "base/task.h" |
19 #include "base/time.h" | 19 #include "base/time.h" |
20 #include "chrome/browser/renderer_host/backing_store_x.h" | 20 #include "chrome/browser/renderer_host/backing_store_x.h" |
21 #include "chrome/browser/renderer_host/gpu_view_host.h" | 21 #include "chrome/browser/renderer_host/gpu_view_host.h" |
22 #include "chrome/browser/renderer_host/render_widget_host.h" | 22 #include "chrome/browser/renderer_host/render_widget_host.h" |
23 #include "chrome/browser/renderer_host/video_layer_x.h" | 23 #include "chrome/browser/renderer_host/video_layer_x.h" |
24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/native_web_keyboard_event.h" | 25 #include "chrome/common/native_web_keyboard_event.h" |
26 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
| 27 #include "gfx/canvas.h" |
27 #include "third_party/WebKit/WebKit/chromium/public/gtk/WebInputEventFactory.h" | 28 #include "third_party/WebKit/WebKit/chromium/public/gtk/WebInputEventFactory.h" |
28 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 29 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
29 #include "views/event.h" | 30 #include "views/event.h" |
30 #include "views/widget/widget.h" | 31 #include "views/widget/widget.h" |
31 | 32 |
32 static const int kMaxWindowWidth = 4000; | 33 static const int kMaxWindowWidth = 4000; |
33 static const int kMaxWindowHeight = 4000; | 34 static const int kMaxWindowHeight = 4000; |
34 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; | 35 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; |
35 | 36 |
36 using WebKit::WebInputEventFactory; | 37 using WebKit::WebInputEventFactory; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 GetRenderWidgetHost()->WasHidden(); | 125 GetRenderWidgetHost()->WasHidden(); |
125 } | 126 } |
126 | 127 |
127 void RenderWidgetHostViewViews::SetSize(const gfx::Size& size) { | 128 void RenderWidgetHostViewViews::SetSize(const gfx::Size& size) { |
128 // This is called when webkit has sent us a Move message. | 129 // This is called when webkit has sent us a Move message. |
129 int width = std::min(size.width(), kMaxWindowWidth); | 130 int width = std::min(size.width(), kMaxWindowWidth); |
130 int height = std::min(size.height(), kMaxWindowHeight); | 131 int height = std::min(size.height(), kMaxWindowHeight); |
131 if (requested_size_.width() != width || | 132 if (requested_size_.width() != width || |
132 requested_size_.height() != height) { | 133 requested_size_.height() != height) { |
133 requested_size_ = gfx::Size(width, height); | 134 requested_size_ = gfx::Size(width, height); |
134 SetBounds(GetViewBounds()); | 135 SetBounds(gfx::Rect(x(), y(), width, height)); |
135 host_->WasResized(); | 136 host_->WasResized(); |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 void RenderWidgetHostViewViews::MovePluginWindows( | 140 void RenderWidgetHostViewViews::MovePluginWindows( |
140 const std::vector<webkit_glue::WebPluginGeometry>& moves) { | 141 const std::vector<webkit_glue::WebPluginGeometry>& moves) { |
141 // TODO(anicolao): NIY | 142 // TODO(anicolao): NIY |
142 NOTIMPLEMENTED(); | 143 NOTIMPLEMENTED(); |
143 } | 144 } |
144 | 145 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 280 } |
280 return gpu_view_host_->CreateBackingStore(size); | 281 return gpu_view_host_->CreateBackingStore(size); |
281 } | 282 } |
282 | 283 |
283 return new BackingStoreX(host_, size, | 284 return new BackingStoreX(host_, size, |
284 x11_util::GetVisualFromGtkWidget(native_view()), | 285 x11_util::GetVisualFromGtkWidget(native_view()), |
285 gtk_widget_get_visual(native_view())->depth); | 286 gtk_widget_get_visual(native_view())->depth); |
286 } | 287 } |
287 | 288 |
288 gfx::NativeView RenderWidgetHostViewViews::native_view() const { | 289 gfx::NativeView RenderWidgetHostViewViews::native_view() const { |
289 return GetWidget()->GetNativeView(); | 290 if (GetWidget()) |
| 291 return GetWidget()->GetNativeView(); |
| 292 return NULL; |
290 } | 293 } |
291 | 294 |
292 VideoLayer* RenderWidgetHostViewViews::AllocVideoLayer(const gfx::Size& size) { | 295 VideoLayer* RenderWidgetHostViewViews::AllocVideoLayer(const gfx::Size& size) { |
293 if (enable_gpu_rendering_) { | 296 if (enable_gpu_rendering_) { |
294 // TODO(scherkus): is it possible for a video layer to be allocated before a | 297 // TODO(scherkus): is it possible for a video layer to be allocated before a |
295 // backing store? | 298 // backing store? |
296 DCHECK(gpu_view_host_.get()) | 299 DCHECK(gpu_view_host_.get()) |
297 << "AllocVideoLayer() called before AllocBackingStore()"; | 300 << "AllocVideoLayer() called before AllocBackingStore()"; |
298 return gpu_view_host_->CreateVideoLayer(size); | 301 return gpu_view_host_->CreateVideoLayer(size); |
299 } | 302 } |
300 | 303 |
301 return new VideoLayerX(host_, size, | 304 return new VideoLayerX(host_, size, |
302 x11_util::GetVisualFromGtkWidget(native_view()), | 305 x11_util::GetVisualFromGtkWidget(native_view()), |
303 gtk_widget_get_visual(native_view())->depth); | 306 gtk_widget_get_visual(native_view())->depth); |
304 } | 307 } |
305 | 308 |
306 void RenderWidgetHostViewViews::SetBackground(const SkBitmap& background) { | 309 void RenderWidgetHostViewViews::SetBackground(const SkBitmap& background) { |
307 RenderWidgetHostView::SetBackground(background); | 310 RenderWidgetHostView::SetBackground(background); |
308 host_->Send(new ViewMsg_SetBackground(host_->routing_id(), background)); | 311 host_->Send(new ViewMsg_SetBackground(host_->routing_id(), background)); |
309 } | 312 } |
310 | 313 |
311 void RenderWidgetHostViewViews::Paint(gfx::Canvas* canvas) { | 314 void RenderWidgetHostViewViews::Paint(gfx::Canvas* canvas) { |
| 315 if (is_hidden_) { |
| 316 return; |
| 317 } |
| 318 |
| 319 // Paint a "hole" in the canvas so that the render of the web page is on |
| 320 // top of whatever else has already been painted in the views hierarchy. |
| 321 // Later views might still get to paint on top. |
| 322 canvas->FillRectInt(SK_ColorBLACK, 0, 0, kMaxWindowWidth, kMaxWindowHeight, |
| 323 SkXfermode::kClear_Mode); |
| 324 |
312 if (enable_gpu_rendering_) { | 325 if (enable_gpu_rendering_) { |
313 // When we're proxying painting, we don't actually display the web page | 326 // When we're proxying painting, we don't actually display the web page |
314 // ourselves. | 327 // ourselves. |
315 if (gpu_view_host_.get()) | 328 if (gpu_view_host_.get()) |
316 gpu_view_host_->OnWindowPainted(); | 329 gpu_view_host_->OnWindowPainted(); |
317 | 330 |
318 // Erase the background. This will prevent a flash of black when resizing | 331 // Erase the background. This will prevent a flash of black when resizing |
319 // or exposing the window. White is usually better than black. | 332 // or exposing the window. White is usually better than black. |
320 return; | 333 return; |
321 } | 334 } |
322 | 335 |
323 // Don't do any painting if the GPU process is rendering directly | 336 // Don't do any painting if the GPU process is rendering directly |
324 // into the View. | 337 // into the View. |
325 RenderWidgetHost* render_widget_host = GetRenderWidgetHost(); | 338 RenderWidgetHost* render_widget_host = GetRenderWidgetHost(); |
326 if (render_widget_host->is_gpu_rendering_active()) { | 339 if (render_widget_host->is_gpu_rendering_active()) { |
327 return; | 340 return; |
328 } | 341 } |
329 | 342 |
330 GdkWindow* window = native_view()->window; | 343 GdkWindow* window = native_view()->window; |
331 DCHECK(!about_to_validate_and_paint_); | 344 DCHECK(!about_to_validate_and_paint_); |
332 | 345 |
333 // TODO(anicolao): get the damage somehow | 346 // TODO(anicolao): get the damage somehow |
334 // invalid_rect_ = damage_rect; | 347 // invalid_rect_ = damage_rect; |
335 invalid_rect_ = bounds(); | 348 invalid_rect_ = bounds(); |
| 349 gfx::Point origin; |
| 350 ConvertPointToWidget(this, &origin); |
| 351 |
336 about_to_validate_and_paint_ = true; | 352 about_to_validate_and_paint_ = true; |
337 BackingStoreX* backing_store = static_cast<BackingStoreX*>( | 353 BackingStoreX* backing_store = static_cast<BackingStoreX*>( |
338 host_->GetBackingStore(true)); | 354 host_->GetBackingStore(true)); |
339 // Calling GetBackingStore maybe have changed |invalid_rect_|... | 355 // Calling GetBackingStore maybe have changed |invalid_rect_|... |
340 about_to_validate_and_paint_ = false; | 356 about_to_validate_and_paint_ = false; |
341 | 357 |
342 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); | 358 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); |
343 paint_rect = paint_rect.Intersect(invalid_rect_); | 359 paint_rect = paint_rect.Intersect(invalid_rect_); |
344 | 360 |
345 if (backing_store) { | 361 if (backing_store) { |
346 // Only render the widget if it is attached to a window; there's a short | 362 // Only render the widget if it is attached to a window; there's a short |
347 // period where this object isn't attached to a window but hasn't been | 363 // period where this object isn't attached to a window but hasn't been |
348 // Destroy()ed yet and it receives paint messages... | 364 // Destroy()ed yet and it receives paint messages... |
349 if (window) { | 365 if (window) { |
350 if (!visually_deemphasized_) { | 366 if (!visually_deemphasized_) { |
351 // In the common case, use XCopyArea. We don't draw more than once, so | 367 // In the common case, use XCopyArea. We don't draw more than once, so |
352 // we don't need to double buffer. | 368 // we don't need to double buffer. |
353 backing_store->XShowRect( | 369 backing_store->XShowRect(origin, |
354 paint_rect, x11_util::GetX11WindowFromGtkWidget(native_view())); | 370 paint_rect, x11_util::GetX11WindowFromGtkWidget(native_view())); |
355 | 371 |
356 // Paint the video layer using XCopyArea. | 372 // Paint the video layer using XCopyArea. |
357 // TODO(scherkus): implement VideoLayerX::CairoShow() for grey | 373 // TODO(scherkus): implement VideoLayerX::CairoShow() for grey |
358 // blending. | 374 // blending. |
359 VideoLayerX* video_layer = static_cast<VideoLayerX*>( | 375 VideoLayerX* video_layer = static_cast<VideoLayerX*>( |
360 host_->video_layer()); | 376 host_->video_layer()); |
361 if (video_layer) | 377 if (video_layer) |
362 video_layer->XShow( | 378 video_layer->XShow( |
363 x11_util::GetX11WindowFromGtkWidget(native_view())); | 379 x11_util::GetX11WindowFromGtkWidget(native_view())); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 } | 539 } |
524 #endif | 540 #endif |
525 | 541 |
526 ShowCurrentCursor(); | 542 ShowCurrentCursor(); |
527 GetRenderWidgetHost()->GotFocus(); | 543 GetRenderWidgetHost()->GotFocus(); |
528 } | 544 } |
529 | 545 |
530 void RenderWidgetHostViewViews::WillLoseFocus() { | 546 void RenderWidgetHostViewViews::WillLoseFocus() { |
531 // If we are showing a context menu, maintain the illusion that webkit has | 547 // If we are showing a context menu, maintain the illusion that webkit has |
532 // focus. | 548 // focus. |
533 if (!is_showing_context_menu_) | 549 if (!is_showing_context_menu_ && !is_hidden_) |
534 GetRenderWidgetHost()->Blur(); | 550 GetRenderWidgetHost()->Blur(); |
535 } | 551 } |
536 | 552 |
537 | 553 |
538 void RenderWidgetHostViewViews::ShowCurrentCursor() { | 554 void RenderWidgetHostViewViews::ShowCurrentCursor() { |
539 // The widget may not have a window. If that's the case, abort mission. This | 555 // The widget may not have a window. If that's the case, abort mission. This |
540 // is the same issue as that explained above in Paint(). | 556 // is the same issue as that explained above in Paint(). |
541 if (!native_view()->window) | 557 if (!native_view() || !native_view()->window) |
542 return; | 558 return; |
543 | 559 |
544 // TODO(anicolao): change to set cursors without GTK | 560 // TODO(anicolao): change to set cursors without GTK |
545 } | 561 } |
546 | 562 |
547 void RenderWidgetHostViewViews::CreatePluginContainer( | 563 void RenderWidgetHostViewViews::CreatePluginContainer( |
548 gfx::PluginWindowHandle id) { | 564 gfx::PluginWindowHandle id) { |
549 // TODO(anicolao): plugin_container_manager_.CreatePluginContainer(id); | 565 // TODO(anicolao): plugin_container_manager_.CreatePluginContainer(id); |
550 } | 566 } |
551 | 567 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 } | 630 } |
615 | 631 |
616 // static | 632 // static |
617 RenderWidgetHostView* | 633 RenderWidgetHostView* |
618 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 634 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
619 gfx::NativeView widget) { | 635 gfx::NativeView widget) { |
620 gpointer user_data = g_object_get_data(G_OBJECT(widget), | 636 gpointer user_data = g_object_get_data(G_OBJECT(widget), |
621 kRenderWidgetHostViewKey); | 637 kRenderWidgetHostViewKey); |
622 return reinterpret_cast<RenderWidgetHostView*>(user_data); | 638 return reinterpret_cast<RenderWidgetHostView*>(user_data); |
623 } | 639 } |
OLD | NEW |