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_win.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/l10n_util_win.h" | 8 #include "app/l10n_util_win.h" |
9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
10 #include "app/win/scoped_prop.h" | 10 #include "app/win/scoped_prop.h" |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 GetWindowRect(&window_rect); | 576 GetWindowRect(&window_rect); |
577 return gfx::Rect(window_rect); | 577 return gfx::Rect(window_rect); |
578 } | 578 } |
579 | 579 |
580 void RenderWidgetHostViewWin::UpdateCursor(const WebCursor& cursor) { | 580 void RenderWidgetHostViewWin::UpdateCursor(const WebCursor& cursor) { |
581 current_cursor_ = cursor; | 581 current_cursor_ = cursor; |
582 UpdateCursorIfOverSelf(); | 582 UpdateCursorIfOverSelf(); |
583 } | 583 } |
584 | 584 |
585 void RenderWidgetHostViewWin::UpdateCursorIfOverSelf() { | 585 void RenderWidgetHostViewWin::UpdateCursorIfOverSelf() { |
586 static HCURSOR kCursorResizeRight = LoadCursor(NULL, IDC_SIZENWSE); | |
587 static HCURSOR kCursorResizeLeft = LoadCursor(NULL, IDC_SIZENESW); | |
588 static HCURSOR kCursorArrow = LoadCursor(NULL, IDC_ARROW); | 586 static HCURSOR kCursorArrow = LoadCursor(NULL, IDC_ARROW); |
589 static HCURSOR kCursorAppStarting = LoadCursor(NULL, IDC_APPSTARTING); | 587 static HCURSOR kCursorAppStarting = LoadCursor(NULL, IDC_APPSTARTING); |
590 static HINSTANCE module_handle = | 588 static HINSTANCE module_handle = |
591 GetModuleHandle(chrome::kBrowserResourcesDll); | 589 GetModuleHandle(chrome::kBrowserResourcesDll); |
592 | 590 |
593 // If the mouse is over our HWND, then update the cursor state immediately. | 591 // If the mouse is over our HWND, then update the cursor state immediately. |
594 CPoint pt; | 592 CPoint pt; |
595 GetCursorPos(&pt); | 593 GetCursorPos(&pt); |
596 if (WindowFromPoint(pt) == m_hWnd) { | 594 if (WindowFromPoint(pt) == m_hWnd) { |
597 BOOL result = ::ScreenToClient(m_hWnd, &pt); | 595 BOOL result = ::ScreenToClient(m_hWnd, &pt); |
598 DCHECK(result); | 596 DCHECK(result); |
599 if (render_widget_host_->GetRootWindowResizerRect().Contains(pt.x, pt.y)) { | 597 // We cannot pass in NULL as the module handle as this would only work for |
600 if (base::i18n::IsRTL()) | 598 // standard win32 cursors. We can also receive cursor types which are |
601 SetCursor(kCursorResizeLeft); | 599 // defined as webkit resources. We need to specify the module handle of |
602 else | 600 // chrome.dll while loading these cursors. |
603 SetCursor(kCursorResizeRight); | 601 HCURSOR display_cursor = current_cursor_.GetCursor(module_handle); |
604 } else { | |
605 // We cannot pass in NULL as the module handle as this would only work for | |
606 // standard win32 cursors. We can also receive cursor types which are | |
607 // defined as webkit resources. We need to specify the module handle of | |
608 // chrome.dll while loading these cursors. | |
609 HCURSOR display_cursor = current_cursor_.GetCursor(module_handle); | |
610 | 602 |
611 // If a page is in the loading state, we want to show the Arrow+Hourglass | 603 // If a page is in the loading state, we want to show the Arrow+Hourglass |
612 // cursor only when the current cursor is the ARROW cursor. In all other | 604 // cursor only when the current cursor is the ARROW cursor. In all other |
613 // cases we should continue to display the current cursor. | 605 // cases we should continue to display the current cursor. |
614 if (is_loading_ && display_cursor == kCursorArrow) | 606 if (is_loading_ && display_cursor == kCursorArrow) |
615 display_cursor = kCursorAppStarting; | 607 display_cursor = kCursorAppStarting; |
616 | 608 |
617 SetCursor(display_cursor); | 609 SetCursor(display_cursor); |
618 } | |
619 } | 610 } |
620 } | 611 } |
621 | 612 |
622 void RenderWidgetHostViewWin::SetIsLoading(bool is_loading) { | 613 void RenderWidgetHostViewWin::SetIsLoading(bool is_loading) { |
623 is_loading_ = is_loading; | 614 is_loading_ = is_loading; |
624 UpdateCursorIfOverSelf(); | 615 UpdateCursorIfOverSelf(); |
625 } | 616 } |
626 | 617 |
627 void RenderWidgetHostViewWin::ImeUpdateTextInputState( | 618 void RenderWidgetHostViewWin::ImeUpdateTextInputState( |
628 WebKit::WebTextInputType type, | 619 WebKit::WebTextInputType type, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 | 673 |
683 // Send the invalid rect in screen coordinates. | 674 // Send the invalid rect in screen coordinates. |
684 gfx::Rect screen_rect = GetViewBounds(); | 675 gfx::Rect screen_rect = GetViewBounds(); |
685 gfx::Rect invalid_screen_rect(damage_bounds); | 676 gfx::Rect invalid_screen_rect(damage_bounds); |
686 invalid_screen_rect.Offset(screen_rect.x(), screen_rect.y()); | 677 invalid_screen_rect.Offset(screen_rect.x(), screen_rect.y()); |
687 | 678 |
688 LPARAM lparam = reinterpret_cast<LPARAM>(&invalid_screen_rect); | 679 LPARAM lparam = reinterpret_cast<LPARAM>(&invalid_screen_rect); |
689 EnumChildWindows(m_hWnd, EnumChildProc, lparam); | 680 EnumChildWindows(m_hWnd, EnumChildProc, lparam); |
690 } | 681 } |
691 | 682 |
692 void RenderWidgetHostViewWin::DrawResizeCorner(const gfx::Rect& paint_rect, | |
693 HDC dc) { | |
694 gfx::Rect resize_corner_rect = | |
695 render_widget_host_->GetRootWindowResizerRect(); | |
696 if (!paint_rect.Intersect(resize_corner_rect).IsEmpty()) { | |
697 SkBitmap* bitmap = ResourceBundle::GetSharedInstance(). | |
698 GetBitmapNamed(IDR_TEXTAREA_RESIZER); | |
699 gfx::CanvasSkia canvas(bitmap->width(), bitmap->height(), false); | |
700 canvas.getDevice()->accessBitmap(true).eraseARGB(0, 0, 0, 0); | |
701 int x = resize_corner_rect.x() + resize_corner_rect.width() - | |
702 bitmap->width(); | |
703 canvas.save(); | |
704 if (base::i18n::IsRTL()) { | |
705 canvas.TranslateInt(bitmap->width(), 0); | |
706 canvas.ScaleInt(-1, 1); | |
707 x = 0; | |
708 } | |
709 canvas.DrawBitmapInt(*bitmap, 0, 0); | |
710 canvas.getTopPlatformDevice().drawToHDC(dc, x, | |
711 resize_corner_rect.y() + resize_corner_rect.height() - | |
712 bitmap->height(), NULL); | |
713 canvas.restore(); | |
714 } | |
715 } | |
716 | |
717 void RenderWidgetHostViewWin::DidUpdateBackingStore( | 683 void RenderWidgetHostViewWin::DidUpdateBackingStore( |
718 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, | 684 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, |
719 const std::vector<gfx::Rect>& copy_rects) { | 685 const std::vector<gfx::Rect>& copy_rects) { |
720 if (is_hidden_) | 686 if (is_hidden_) |
721 return; | 687 return; |
722 | 688 |
723 // Schedule invalidations first so that the ScrollWindowEx call is closer to | 689 // Schedule invalidations first so that the ScrollWindowEx call is closer to |
724 // Redraw. That minimizes chances of "flicker" resulting if the screen | 690 // Redraw. That minimizes chances of "flicker" resulting if the screen |
725 // refreshes before we have a chance to paint the exposed area. Somewhat | 691 // refreshes before we have a chance to paint the exposed area. Somewhat |
726 // surprisingly, this ordering matters. | 692 // surprisingly, this ordering matters. |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 // Blit only the damaged regions from the backing store. | 907 // Blit only the damaged regions from the backing store. |
942 DWORD data_size = GetRegionData(damage_region, 0, NULL); | 908 DWORD data_size = GetRegionData(damage_region, 0, NULL); |
943 scoped_array<char> region_data_buf(new char[data_size]); | 909 scoped_array<char> region_data_buf(new char[data_size]); |
944 RGNDATA* region_data = reinterpret_cast<RGNDATA*>(region_data_buf.get()); | 910 RGNDATA* region_data = reinterpret_cast<RGNDATA*>(region_data_buf.get()); |
945 GetRegionData(damage_region, data_size, region_data); | 911 GetRegionData(damage_region, data_size, region_data); |
946 | 912 |
947 RECT* region_rects = reinterpret_cast<RECT*>(region_data->Buffer); | 913 RECT* region_rects = reinterpret_cast<RECT*>(region_data->Buffer); |
948 for (DWORD i = 0; i < region_data->rdh.nCount; ++i) { | 914 for (DWORD i = 0; i < region_data->rdh.nCount; ++i) { |
949 gfx::Rect paint_rect = bitmap_rect.Intersect(gfx::Rect(region_rects[i])); | 915 gfx::Rect paint_rect = bitmap_rect.Intersect(gfx::Rect(region_rects[i])); |
950 if (!paint_rect.IsEmpty()) { | 916 if (!paint_rect.IsEmpty()) { |
951 DrawResizeCorner(paint_rect, backing_store->hdc()); | |
952 if (visually_deemphasized_) { | 917 if (visually_deemphasized_) { |
953 DrawDeemphasized(paint_rect, backing_store->hdc(), paint_dc.m_hDC); | 918 DrawDeemphasized(paint_rect, backing_store->hdc(), paint_dc.m_hDC); |
954 } else { | 919 } else { |
955 BitBlt(paint_dc.m_hDC, | 920 BitBlt(paint_dc.m_hDC, |
956 paint_rect.x(), | 921 paint_rect.x(), |
957 paint_rect.y(), | 922 paint_rect.y(), |
958 paint_rect.width(), | 923 paint_rect.width(), |
959 paint_rect.height(), | 924 paint_rect.height(), |
960 backing_store->hdc(), | 925 backing_store->hdc(), |
961 paint_rect.x(), | 926 paint_rect.x(), |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 // TabContents first in the case of popups. If we do, we would need to | 1234 // TabContents first in the case of popups. If we do, we would need to |
1270 // convert the click from the popup window coordinates to the TabContents' | 1235 // convert the click from the popup window coordinates to the TabContents' |
1271 // window coordinates. For now we don't forward the message in that case to | 1236 // window coordinates. For now we don't forward the message in that case to |
1272 // address bug #907474. | 1237 // address bug #907474. |
1273 // Note: GetParent() on popup windows returns the top window and not the | 1238 // Note: GetParent() on popup windows returns the top window and not the |
1274 // parent the window was created with (the parent and the owner of the popup | 1239 // parent the window was created with (the parent and the owner of the popup |
1275 // is the first non-child view of the view that was specified to the create | 1240 // is the first non-child view of the view that was specified to the create |
1276 // call). So the TabContents window would have to be specified to the | 1241 // call). So the TabContents window would have to be specified to the |
1277 // RenderViewHostHWND as there is no way to retrieve it from the HWND. | 1242 // RenderViewHostHWND as there is no way to retrieve it from the HWND. |
1278 if (!close_on_deactivate_) { // Don't forward if the container is a popup. | 1243 if (!close_on_deactivate_) { // Don't forward if the container is a popup. |
1279 if (message == WM_LBUTTONDOWN) { | |
1280 // If we get clicked on, where the resize corner is drawn, we delegate the | |
1281 // message to the root window, with the proper HTBOTTOMXXX wparam so that | |
1282 // Windows can take care of the resizing for us. | |
1283 if (render_widget_host_ && | |
1284 render_widget_host_->GetRootWindowResizerRect(). | |
1285 Contains(GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam))) { | |
1286 WPARAM wparam = HTBOTTOMRIGHT; | |
1287 if (base::i18n::IsRTL()) | |
1288 wparam = HTBOTTOMLEFT; | |
1289 HWND root_hwnd = ::GetAncestor(m_hWnd, GA_ROOT); | |
1290 if (SendMessage(root_hwnd, WM_NCLBUTTONDOWN, wparam, lparam) == 0) | |
1291 return 0; | |
1292 } | |
1293 } | |
1294 switch (message) { | 1244 switch (message) { |
1295 case WM_LBUTTONDOWN: | 1245 case WM_LBUTTONDOWN: |
1296 case WM_MBUTTONDOWN: | 1246 case WM_MBUTTONDOWN: |
1297 case WM_RBUTTONDOWN: | 1247 case WM_RBUTTONDOWN: |
1298 // Finish the ongoing composition whenever a mouse click happens. | 1248 // Finish the ongoing composition whenever a mouse click happens. |
1299 // It matches IE's behavior. | 1249 // It matches IE's behavior. |
1300 ime_input_.CleanupComposition(m_hWnd); | 1250 ime_input_.CleanupComposition(m_hWnd); |
1301 // Fall through. | 1251 // Fall through. |
1302 case WM_MOUSEMOVE: | 1252 case WM_MOUSEMOVE: |
1303 case WM_MOUSELEAVE: { | 1253 case WM_MOUSELEAVE: { |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 1659 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
1710 gfx::NativeView native_view) { | 1660 gfx::NativeView native_view) { |
1711 if (::IsWindow(native_view)) { | 1661 if (::IsWindow(native_view)) { |
1712 HANDLE raw_render_host_view = ::GetProp(native_view, | 1662 HANDLE raw_render_host_view = ::GetProp(native_view, |
1713 kRenderWidgetHostViewKey); | 1663 kRenderWidgetHostViewKey); |
1714 if (raw_render_host_view) | 1664 if (raw_render_host_view) |
1715 return reinterpret_cast<RenderWidgetHostView*>(raw_render_host_view); | 1665 return reinterpret_cast<RenderWidgetHostView*>(raw_render_host_view); |
1716 } | 1666 } |
1717 return NULL; | 1667 return NULL; |
1718 } | 1668 } |
OLD | NEW |