OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/render_widget_host_hwnd.h" | 5 #include "chrome/browser/render_widget_host_hwnd.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/gfx/gdi_util.h" | 8 #include "base/gfx/gdi_util.h" |
| 9 #include "base/gfx/platform_canvas.h" |
9 #include "base/gfx/rect.h" | 10 #include "base/gfx/rect.h" |
10 #include "base/histogram.h" | 11 #include "base/histogram.h" |
11 #include "base/win_util.h" | 12 #include "base/win_util.h" |
12 #include "chrome/browser/browser_accessibility.h" | 13 #include "chrome/browser/browser_accessibility.h" |
13 #include "chrome/browser/browser_accessibility_manager.h" | 14 #include "chrome/browser/browser_accessibility_manager.h" |
14 #include "chrome/browser/browser_trial.h" | 15 #include "chrome/browser/browser_trial.h" |
| 16 #include "chrome/browser/controller.h" |
15 #include "chrome/browser/render_process_host.h" | 17 #include "chrome/browser/render_process_host.h" |
16 // TODO(beng): (Cleanup) we should not need to include this file... see comment | 18 // TODO(beng): (Cleanup) we should not need to include this file... see comment |
17 // in |DidBecomeSelected|. | 19 // in |DidBecomeSelected|. |
18 #include "chrome/browser/render_view_host.h" | 20 #include "chrome/browser/render_view_host.h" |
19 #include "chrome/browser/render_widget_host.h" | 21 #include "chrome/browser/render_widget_host.h" |
20 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
21 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/l10n_util.h" | 24 #include "chrome/common/l10n_util.h" |
| 25 #include "chrome/common/notification_service.h" |
23 #include "chrome/common/plugin_messages.h" | 26 #include "chrome/common/plugin_messages.h" |
24 #include "chrome/common/win_util.h" | 27 #include "chrome/common/win_util.h" |
25 #include "chrome/views/container_win.h" | 28 #include "chrome/views/container_win.h" |
26 #include "webkit/glue/webcursor.h" | 29 #include "webkit/glue/webcursor.h" |
27 | 30 |
28 // Tooltips will wrap after this width. Yes, wrap. Imagine that! | 31 // Tooltips will wrap after this width. Yes, wrap. Imagine that! |
29 static const int kTooltipMaxWidthPixels = 300; | 32 static const int kTooltipMaxWidthPixels = 300; |
30 | 33 |
31 // Maximum number of characters we allow in a tooltip. | 34 // Maximum number of characters we allow in a tooltip. |
32 static const int kMaxTooltipLength = 1024; | 35 static const int kMaxTooltipLength = 1024; |
(...skipping 11 matching lines...) Expand all Loading... |
44 ime_notification_(false), | 47 ime_notification_(false), |
45 is_hidden_(false), | 48 is_hidden_(false), |
46 close_on_deactivate_(false), | 49 close_on_deactivate_(false), |
47 tooltip_hwnd_(NULL), | 50 tooltip_hwnd_(NULL), |
48 tooltip_showing_(false), | 51 tooltip_showing_(false), |
49 shutdown_factory_(this), | 52 shutdown_factory_(this), |
50 parent_hwnd_(NULL), | 53 parent_hwnd_(NULL), |
51 is_loading_(false) { | 54 is_loading_(false) { |
52 renderer_accessible_ = | 55 renderer_accessible_ = |
53 CommandLine().HasSwitch(switches::kEnableRendererAccessibility); | 56 CommandLine().HasSwitch(switches::kEnableRendererAccessibility); |
| 57 |
| 58 NotificationService::current()->AddObserver( |
| 59 this, |
| 60 NOTIFY_THREEDEE_TOGGLED, |
| 61 NotificationService::AllSources()); |
54 } | 62 } |
55 | 63 |
56 RenderWidgetHostHWND::~RenderWidgetHostHWND() { | 64 RenderWidgetHostHWND::~RenderWidgetHostHWND() { |
| 65 NotificationService::current()->RemoveObserver( |
| 66 this, |
| 67 NOTIFY_THREEDEE_TOGGLED, |
| 68 NotificationService::AllSources()); |
| 69 |
57 if (real_cursor_type_ == WebCursor::CUSTOM) | 70 if (real_cursor_type_ == WebCursor::CUSTOM) |
58 DestroyIcon(real_cursor_); | 71 DestroyIcon(real_cursor_); |
59 ResetTooltip(); | 72 ResetTooltip(); |
60 } | 73 } |
61 | 74 |
62 /////////////////////////////////////////////////////////////////////////////// | 75 /////////////////////////////////////////////////////////////////////////////// |
63 // RenderWidgetHostHWND, RenderWidgetHostView implementation: | 76 // RenderWidgetHostHWND, RenderWidgetHostView implementation: |
64 | 77 |
65 void RenderWidgetHostHWND::DidBecomeSelected() { | 78 void RenderWidgetHostHWND::DidBecomeSelected() { |
66 if (!is_hidden_) | 79 if (!is_hidden_) |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 render_widget_host_->GetBackingStore(); | 380 render_widget_host_->GetBackingStore(); |
368 | 381 |
369 if (backing_store) { | 382 if (backing_store) { |
370 gfx::Rect damaged_rect(paint_dc.m_ps.rcPaint); | 383 gfx::Rect damaged_rect(paint_dc.m_ps.rcPaint); |
371 | 384 |
372 gfx::Rect bitmap_rect( | 385 gfx::Rect bitmap_rect( |
373 0, 0, backing_store->size().width(), backing_store->size().height()); | 386 0, 0, backing_store->size().width(), backing_store->size().height()); |
374 | 387 |
375 gfx::Rect paint_rect = bitmap_rect.Intersect(damaged_rect); | 388 gfx::Rect paint_rect = bitmap_rect.Intersect(damaged_rect); |
376 if (!paint_rect.IsEmpty()) { | 389 if (!paint_rect.IsEmpty()) { |
377 BitBlt(paint_dc.m_hDC, | 390 if (g_threedee_enabled) { |
378 paint_rect.x(), | 391 // Do 3D effect --------------------------------------------------------
-- |
379 paint_rect.y(), | 392 |
380 paint_rect.width(), | 393 const int kOverhang = 5; |
381 paint_rect.height(), | 394 |
382 backing_store->dc(), | 395 // Paint the pixels into the canvas. |
383 paint_rect.x(), | 396 gfx::PlatformCanvas effect_canvas(bitmap_rect.width(), |
384 paint_rect.y(), | 397 bitmap_rect.height(), true); |
385 SRCCOPY); | 398 HDC effect_dc = effect_canvas.beginPlatformPaint(); |
| 399 BitBlt(effect_dc, |
| 400 0, |
| 401 0, |
| 402 bitmap_rect.width(), |
| 403 bitmap_rect.height(), |
| 404 backing_store->dc(), |
| 405 0, |
| 406 0, |
| 407 SRCCOPY); |
| 408 |
| 409 // We need to process the pixels manually, get them out. |
| 410 SkBitmap effect_bitmap = |
| 411 effect_canvas.getTopPlatformDevice().accessBitmap(true); |
| 412 SkAutoLockPixels effect_lock(effect_bitmap); |
| 413 |
| 414 // Shift blue to the right. This will make the page pop into the screen |
| 415 // for glasses with red on the left and blue on the right. |
| 416 for (int y = 0; y < bitmap_rect.height(); y++) { |
| 417 uint32* row = effect_bitmap.getAddr32(0, y); |
| 418 for (int x = 0; x < bitmap_rect.width() - kOverhang; x++) |
| 419 row[x] = (row[x] & 0xFF00FFFF) | (row[x + kOverhang] & 0x00FF0000); |
| 420 } |
| 421 |
| 422 // Shift red to the right. |
| 423 for (int y = 0; y < bitmap_rect.height(); y++) { |
| 424 uint32* row = effect_bitmap.getAddr32(0, y); |
| 425 for (int x = bitmap_rect.width() - 1; x >= kOverhang; x--) |
| 426 row[x] = (row[x] & 0xFFFFFF00) | (row[x - kOverhang] & 0x000000FF); |
| 427 } |
| 428 |
| 429 // We actually need to draw more than the paint rect, since the modified |
| 430 // pixels will spill out of their bounds due to shifting. |
| 431 gfx::Rect final_rect = paint_rect; |
| 432 final_rect.Inset(-kOverhang, 0); |
| 433 final_rect = final_rect.Intersect(bitmap_rect); |
| 434 |
| 435 BitBlt(paint_dc.m_hDC, |
| 436 final_rect.x(), |
| 437 final_rect.y(), |
| 438 final_rect.width(), |
| 439 final_rect.height(), |
| 440 effect_dc, |
| 441 final_rect.x(), |
| 442 final_rect.y(), |
| 443 SRCCOPY); |
| 444 |
| 445 } else { |
| 446 // Regular painting ---------------------------------------------------- |
| 447 BitBlt(paint_dc.m_hDC, |
| 448 paint_rect.x(), |
| 449 paint_rect.y(), |
| 450 paint_rect.width(), |
| 451 paint_rect.height(), |
| 452 backing_store->dc(), |
| 453 paint_rect.x(), |
| 454 paint_rect.y(), |
| 455 SRCCOPY); |
| 456 } |
386 } | 457 } |
387 | 458 |
388 // Fill the remaining portion of the damaged_rect with white | 459 // Fill the remaining portion of the damaged_rect with white |
389 if (damaged_rect.right() > bitmap_rect.right()) { | 460 if (damaged_rect.right() > bitmap_rect.right()) { |
390 RECT r; | 461 RECT r; |
391 r.left = std::max(bitmap_rect.right(), damaged_rect.x()); | 462 r.left = std::max(bitmap_rect.right(), damaged_rect.x()); |
392 r.right = damaged_rect.right(); | 463 r.right = damaged_rect.right(); |
393 r.top = damaged_rect.y(); | 464 r.top = damaged_rect.y(); |
394 r.bottom = std::min(bitmap_rect.bottom(), damaged_rect.bottom()); | 465 r.bottom = std::min(bitmap_rect.bottom(), damaged_rect.bottom()); |
395 paint_dc.FillRect(&r, white_brush); | 466 paint_dc.FillRect(&r, white_brush); |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 static_cast<IAccessible*>(browser_accessibility_root_)); | 890 static_cast<IAccessible*>(browser_accessibility_root_)); |
820 } | 891 } |
821 return reference_result; | 892 return reference_result; |
822 } | 893 } |
823 | 894 |
824 void RenderWidgetHostHWND::OnFinalMessage(HWND window) { | 895 void RenderWidgetHostHWND::OnFinalMessage(HWND window) { |
825 render_widget_host_->ViewDestroyed(); | 896 render_widget_host_->ViewDestroyed(); |
826 delete this; | 897 delete this; |
827 } | 898 } |
828 | 899 |
| 900 void RenderWidgetHostHWND::Observe(NotificationType type, |
| 901 const NotificationSource& source, |
| 902 const NotificationDetails& details) { |
| 903 // Redraw the window when the user changes this setting. |
| 904 if (type == NOTIFY_THREEDEE_TOGGLED) |
| 905 ::InvalidateRect(m_hWnd, NULL, TRUE); |
| 906 } |
| 907 |
829 void RenderWidgetHostHWND::TrackMouseLeave(bool track) { | 908 void RenderWidgetHostHWND::TrackMouseLeave(bool track) { |
830 if (track == track_mouse_leave_) | 909 if (track == track_mouse_leave_) |
831 return; | 910 return; |
832 track_mouse_leave_ = track; | 911 track_mouse_leave_ = track; |
833 | 912 |
834 DCHECK(m_hWnd); | 913 DCHECK(m_hWnd); |
835 | 914 |
836 TRACKMOUSEEVENT tme; | 915 TRACKMOUSEEVENT tme; |
837 tme.cbSize = sizeof(TRACKMOUSEEVENT); | 916 tme.cbSize = sizeof(TRACKMOUSEEVENT); |
838 tme.dwFlags = TME_LEAVE; | 917 tme.dwFlags = TME_LEAVE; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 | 967 |
889 return TRUE; | 968 return TRUE; |
890 } | 969 } |
891 | 970 |
892 void RenderWidgetHostHWND::ShutdownHost() { | 971 void RenderWidgetHostHWND::ShutdownHost() { |
893 shutdown_factory_.RevokeAll(); | 972 shutdown_factory_.RevokeAll(); |
894 render_widget_host_->Shutdown(); | 973 render_widget_host_->Shutdown(); |
895 // Do not touch any members at this point, |this| has been deleted. | 974 // Do not touch any members at this point, |this| has been deleted. |
896 } | 975 } |
897 | 976 |
OLD | NEW |