| 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/render_widget_host.h" | 21 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/native_web_keyboard_event.h" | 23 #include "chrome/common/native_web_keyboard_event.h" |
| 24 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/render_messages.h" |
| 25 #include "gfx/canvas.h" |
| 25 #include "third_party/WebKit/WebKit/chromium/public/gtk/WebInputEventFactory.h" | 26 #include "third_party/WebKit/WebKit/chromium/public/gtk/WebInputEventFactory.h" |
| 26 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 27 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
| 27 #include "views/event.h" | 28 #include "views/event.h" |
| 28 #include "views/widget/widget.h" | 29 #include "views/widget/widget.h" |
| 29 | 30 |
| 30 static const int kMaxWindowWidth = 4000; | 31 static const int kMaxWindowWidth = 4000; |
| 31 static const int kMaxWindowHeight = 4000; | 32 static const int kMaxWindowHeight = 4000; |
| 32 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; | 33 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; |
| 33 | 34 |
| 34 using WebKit::WebInputEventFactory; | 35 using WebKit::WebInputEventFactory; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 GetRenderWidgetHost()->WasHidden(); | 117 GetRenderWidgetHost()->WasHidden(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void RenderWidgetHostViewViews::SetSize(const gfx::Size& size) { | 120 void RenderWidgetHostViewViews::SetSize(const gfx::Size& size) { |
| 120 // This is called when webkit has sent us a Move message. | 121 // This is called when webkit has sent us a Move message. |
| 121 int width = std::min(size.width(), kMaxWindowWidth); | 122 int width = std::min(size.width(), kMaxWindowWidth); |
| 122 int height = std::min(size.height(), kMaxWindowHeight); | 123 int height = std::min(size.height(), kMaxWindowHeight); |
| 123 if (requested_size_.width() != width || | 124 if (requested_size_.width() != width || |
| 124 requested_size_.height() != height) { | 125 requested_size_.height() != height) { |
| 125 requested_size_ = gfx::Size(width, height); | 126 requested_size_ = gfx::Size(width, height); |
| 126 SetBounds(x(), y(), requested_size_.width(), requested_size_.height()); | 127 SetBounds(gfx::Rect(x(), y(), width, height)); |
| 127 host_->WasResized(); | 128 host_->WasResized(); |
| 128 } | 129 } |
| 129 } | 130 } |
| 130 | 131 |
| 131 void RenderWidgetHostViewViews::MovePluginWindows( | 132 void RenderWidgetHostViewViews::MovePluginWindows( |
| 132 const std::vector<webkit_glue::WebPluginGeometry>& moves) { | 133 const std::vector<webkit_glue::WebPluginGeometry>& moves) { |
| 133 // TODO(anicolao): NIY | 134 // TODO(anicolao): NIY |
| 134 NOTIMPLEMENTED(); | 135 NOTIMPLEMENTED(); |
| 135 } | 136 } |
| 136 | 137 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 259 } |
| 259 | 260 |
| 260 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( | 261 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( |
| 261 const gfx::Size& size) { | 262 const gfx::Size& size) { |
| 262 return new BackingStoreX(host_, size, | 263 return new BackingStoreX(host_, size, |
| 263 x11_util::GetVisualFromGtkWidget(native_view()), | 264 x11_util::GetVisualFromGtkWidget(native_view()), |
| 264 gtk_widget_get_visual(native_view())->depth); | 265 gtk_widget_get_visual(native_view())->depth); |
| 265 } | 266 } |
| 266 | 267 |
| 267 gfx::NativeView RenderWidgetHostViewViews::native_view() const { | 268 gfx::NativeView RenderWidgetHostViewViews::native_view() const { |
| 268 return GetWidget()->GetNativeView(); | 269 if (GetWidget()) |
| 270 return GetWidget()->GetNativeView(); |
| 271 return NULL; |
| 269 } | 272 } |
| 270 | 273 |
| 271 void RenderWidgetHostViewViews::SetBackground(const SkBitmap& background) { | 274 void RenderWidgetHostViewViews::SetBackground(const SkBitmap& background) { |
| 272 RenderWidgetHostView::SetBackground(background); | 275 RenderWidgetHostView::SetBackground(background); |
| 273 host_->Send(new ViewMsg_SetBackground(host_->routing_id(), background)); | 276 host_->Send(new ViewMsg_SetBackground(host_->routing_id(), background)); |
| 274 } | 277 } |
| 275 | 278 |
| 276 void RenderWidgetHostViewViews::Paint(gfx::Canvas* canvas) { | 279 void RenderWidgetHostViewViews::Paint(gfx::Canvas* canvas) { |
| 280 if (is_hidden_) { |
| 281 return; |
| 282 } |
| 283 |
| 284 // Paint a "hole" in the canvas so that the render of the web page is on |
| 285 // top of whatever else has already been painted in the views hierarchy. |
| 286 // Later views might still get to paint on top. |
| 287 canvas->FillRectInt(SK_ColorBLACK, 0, 0, kMaxWindowWidth, kMaxWindowHeight, |
| 288 SkXfermode::kClear_Mode); |
| 289 |
| 277 // Don't do any painting if the GPU process is rendering directly | 290 // Don't do any painting if the GPU process is rendering directly |
| 278 // into the View. | 291 // into the View. |
| 279 RenderWidgetHost* render_widget_host = GetRenderWidgetHost(); | 292 RenderWidgetHost* render_widget_host = GetRenderWidgetHost(); |
| 280 if (render_widget_host->is_gpu_rendering_active()) { | 293 if (render_widget_host->is_gpu_rendering_active()) { |
| 281 return; | 294 return; |
| 282 } | 295 } |
| 283 | 296 |
| 284 GdkWindow* window = native_view()->window; | 297 GdkWindow* window = native_view()->window; |
| 285 DCHECK(!about_to_validate_and_paint_); | 298 DCHECK(!about_to_validate_and_paint_); |
| 286 | 299 |
| 287 // TODO(anicolao): get the damage somehow | 300 // TODO(anicolao): get the damage somehow |
| 288 // invalid_rect_ = damage_rect; | 301 // invalid_rect_ = damage_rect; |
| 289 invalid_rect_ = bounds(); | 302 invalid_rect_ = bounds(); |
| 303 gfx::Point origin; |
| 304 ConvertPointToWidget(this, &origin); |
| 305 |
| 290 about_to_validate_and_paint_ = true; | 306 about_to_validate_and_paint_ = true; |
| 291 BackingStoreX* backing_store = static_cast<BackingStoreX*>( | 307 BackingStoreX* backing_store = static_cast<BackingStoreX*>( |
| 292 host_->GetBackingStore(true)); | 308 host_->GetBackingStore(true)); |
| 293 // Calling GetBackingStore maybe have changed |invalid_rect_|... | 309 // Calling GetBackingStore maybe have changed |invalid_rect_|... |
| 294 about_to_validate_and_paint_ = false; | 310 about_to_validate_and_paint_ = false; |
| 295 | 311 |
| 296 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); | 312 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); |
| 297 paint_rect = paint_rect.Intersect(invalid_rect_); | 313 paint_rect = paint_rect.Intersect(invalid_rect_); |
| 298 | 314 |
| 299 if (backing_store) { | 315 if (backing_store) { |
| 300 // Only render the widget if it is attached to a window; there's a short | 316 // Only render the widget if it is attached to a window; there's a short |
| 301 // period where this object isn't attached to a window but hasn't been | 317 // period where this object isn't attached to a window but hasn't been |
| 302 // Destroy()ed yet and it receives paint messages... | 318 // Destroy()ed yet and it receives paint messages... |
| 303 if (window) { | 319 if (window) { |
| 304 if (!visually_deemphasized_) { | 320 if (!visually_deemphasized_) { |
| 305 // In the common case, use XCopyArea. We don't draw more than once, so | 321 // In the common case, use XCopyArea. We don't draw more than once, so |
| 306 // we don't need to double buffer. | 322 // we don't need to double buffer. |
| 307 backing_store->XShowRect( | 323 backing_store->XShowRect(origin, |
| 308 paint_rect, x11_util::GetX11WindowFromGtkWidget(native_view())); | 324 paint_rect, x11_util::GetX11WindowFromGtkWidget(native_view())); |
| 309 } else { | 325 } else { |
| 310 // If the grey blend is showing, we make two drawing calls. Use double | 326 // If the grey blend is showing, we make two drawing calls. Use double |
| 311 // buffering to prevent flicker. Use CairoShowRect because XShowRect | 327 // buffering to prevent flicker. Use CairoShowRect because XShowRect |
| 312 // shortcuts GDK's double buffering. | 328 // shortcuts GDK's double buffering. |
| 313 GdkRectangle rect = { paint_rect.x(), paint_rect.y(), | 329 GdkRectangle rect = { paint_rect.x(), paint_rect.y(), |
| 314 paint_rect.width(), paint_rect.height() }; | 330 paint_rect.width(), paint_rect.height() }; |
| 315 gdk_window_begin_paint_rect(window, &rect); | 331 gdk_window_begin_paint_rect(window, &rect); |
| 316 | 332 |
| 317 backing_store->CairoShowRect(paint_rect, GDK_DRAWABLE(window)); | 333 backing_store->CairoShowRect(paint_rect, GDK_DRAWABLE(window)); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 484 } |
| 469 #endif | 485 #endif |
| 470 | 486 |
| 471 ShowCurrentCursor(); | 487 ShowCurrentCursor(); |
| 472 GetRenderWidgetHost()->GotFocus(); | 488 GetRenderWidgetHost()->GotFocus(); |
| 473 } | 489 } |
| 474 | 490 |
| 475 void RenderWidgetHostViewViews::WillLoseFocus() { | 491 void RenderWidgetHostViewViews::WillLoseFocus() { |
| 476 // If we are showing a context menu, maintain the illusion that webkit has | 492 // If we are showing a context menu, maintain the illusion that webkit has |
| 477 // focus. | 493 // focus. |
| 478 if (!is_showing_context_menu_) | 494 if (!is_showing_context_menu_ && !is_hidden_) |
| 479 GetRenderWidgetHost()->Blur(); | 495 GetRenderWidgetHost()->Blur(); |
| 480 } | 496 } |
| 481 | 497 |
| 482 | 498 |
| 483 void RenderWidgetHostViewViews::ShowCurrentCursor() { | 499 void RenderWidgetHostViewViews::ShowCurrentCursor() { |
| 484 // The widget may not have a window. If that's the case, abort mission. This | 500 // The widget may not have a window. If that's the case, abort mission. This |
| 485 // is the same issue as that explained above in Paint(). | 501 // is the same issue as that explained above in Paint(). |
| 486 if (!native_view()->window) | 502 if (!native_view() || !native_view()->window) |
| 487 return; | 503 return; |
| 488 | 504 |
| 489 // TODO(anicolao): change to set cursors without GTK | 505 // TODO(anicolao): change to set cursors without GTK |
| 490 } | 506 } |
| 491 | 507 |
| 492 void RenderWidgetHostViewViews::CreatePluginContainer( | 508 void RenderWidgetHostViewViews::CreatePluginContainer( |
| 493 gfx::PluginWindowHandle id) { | 509 gfx::PluginWindowHandle id) { |
| 494 // TODO(anicolao): plugin_container_manager_.CreatePluginContainer(id); | 510 // TODO(anicolao): plugin_container_manager_.CreatePluginContainer(id); |
| 495 } | 511 } |
| 496 | 512 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 } | 575 } |
| 560 | 576 |
| 561 // static | 577 // static |
| 562 RenderWidgetHostView* | 578 RenderWidgetHostView* |
| 563 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 579 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
| 564 gfx::NativeView widget) { | 580 gfx::NativeView widget) { |
| 565 gpointer user_data = g_object_get_data(G_OBJECT(widget), | 581 gpointer user_data = g_object_get_data(G_OBJECT(widget), |
| 566 kRenderWidgetHostViewKey); | 582 kRenderWidgetHostViewKey); |
| 567 return reinterpret_cast<RenderWidgetHostView*>(user_data); | 583 return reinterpret_cast<RenderWidgetHostView*>(user_data); |
| 568 } | 584 } |
| OLD | NEW |