Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: chrome/browser/renderer_host/render_widget_host_view_win.cc

Issue 3547008: Handle resize corner layout entirely in the platform BrowserWindow*/BrowserView* code... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 GetWindowRect(&window_rect); 571 GetWindowRect(&window_rect);
572 return gfx::Rect(window_rect); 572 return gfx::Rect(window_rect);
573 } 573 }
574 574
575 void RenderWidgetHostViewWin::UpdateCursor(const WebCursor& cursor) { 575 void RenderWidgetHostViewWin::UpdateCursor(const WebCursor& cursor) {
576 current_cursor_ = cursor; 576 current_cursor_ = cursor;
577 UpdateCursorIfOverSelf(); 577 UpdateCursorIfOverSelf();
578 } 578 }
579 579
580 void RenderWidgetHostViewWin::UpdateCursorIfOverSelf() { 580 void RenderWidgetHostViewWin::UpdateCursorIfOverSelf() {
581 static HCURSOR kCursorResizeRight = LoadCursor(NULL, IDC_SIZENWSE);
582 static HCURSOR kCursorResizeLeft = LoadCursor(NULL, IDC_SIZENESW);
583 static HCURSOR kCursorArrow = LoadCursor(NULL, IDC_ARROW); 581 static HCURSOR kCursorArrow = LoadCursor(NULL, IDC_ARROW);
584 static HCURSOR kCursorAppStarting = LoadCursor(NULL, IDC_APPSTARTING); 582 static HCURSOR kCursorAppStarting = LoadCursor(NULL, IDC_APPSTARTING);
585 static HINSTANCE module_handle = 583 static HINSTANCE module_handle =
586 GetModuleHandle(chrome::kBrowserResourcesDll); 584 GetModuleHandle(chrome::kBrowserResourcesDll);
587 585
588 // If the mouse is over our HWND, then update the cursor state immediately. 586 // If the mouse is over our HWND, then update the cursor state immediately.
589 CPoint pt; 587 CPoint pt;
590 GetCursorPos(&pt); 588 GetCursorPos(&pt);
591 if (WindowFromPoint(pt) == m_hWnd) { 589 if (WindowFromPoint(pt) == m_hWnd) {
592 BOOL result = ::ScreenToClient(m_hWnd, &pt); 590 BOOL result = ::ScreenToClient(m_hWnd, &pt);
593 DCHECK(result); 591 DCHECK(result);
594 if (render_widget_host_->GetRootWindowResizerRect().Contains(pt.x, pt.y)) { 592 // We cannot pass in NULL as the module handle as this would only work for
595 if (base::i18n::IsRTL()) 593 // standard win32 cursors. We can also receive cursor types which are
596 SetCursor(kCursorResizeLeft); 594 // defined as webkit resources. We need to specify the module handle of
597 else 595 // chrome.dll while loading these cursors.
598 SetCursor(kCursorResizeRight); 596 HCURSOR display_cursor = current_cursor_.GetCursor(module_handle);
599 } else {
600 // We cannot pass in NULL as the module handle as this would only work for
601 // standard win32 cursors. We can also receive cursor types which are
602 // defined as webkit resources. We need to specify the module handle of
603 // chrome.dll while loading these cursors.
604 HCURSOR display_cursor = current_cursor_.GetCursor(module_handle);
605 597
606 // If a page is in the loading state, we want to show the Arrow+Hourglass 598 // If a page is in the loading state, we want to show the Arrow+Hourglass
607 // cursor only when the current cursor is the ARROW cursor. In all other 599 // cursor only when the current cursor is the ARROW cursor. In all other
608 // cases we should continue to display the current cursor. 600 // cases we should continue to display the current cursor.
609 if (is_loading_ && display_cursor == kCursorArrow) 601 if (is_loading_ && display_cursor == kCursorArrow)
610 display_cursor = kCursorAppStarting; 602 display_cursor = kCursorAppStarting;
611 603
612 SetCursor(display_cursor); 604 SetCursor(display_cursor);
613 }
614 } 605 }
615 } 606 }
616 607
617 void RenderWidgetHostViewWin::SetIsLoading(bool is_loading) { 608 void RenderWidgetHostViewWin::SetIsLoading(bool is_loading) {
618 is_loading_ = is_loading; 609 is_loading_ = is_loading;
619 UpdateCursorIfOverSelf(); 610 UpdateCursorIfOverSelf();
620 } 611 }
621 612
622 void RenderWidgetHostViewWin::ImeUpdateTextInputState( 613 void RenderWidgetHostViewWin::ImeUpdateTextInputState(
623 WebKit::WebTextInputType type, 614 WebKit::WebTextInputType type,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 668
678 // Send the invalid rect in screen coordinates. 669 // Send the invalid rect in screen coordinates.
679 gfx::Rect screen_rect = GetViewBounds(); 670 gfx::Rect screen_rect = GetViewBounds();
680 gfx::Rect invalid_screen_rect(damage_bounds); 671 gfx::Rect invalid_screen_rect(damage_bounds);
681 invalid_screen_rect.Offset(screen_rect.x(), screen_rect.y()); 672 invalid_screen_rect.Offset(screen_rect.x(), screen_rect.y());
682 673
683 LPARAM lparam = reinterpret_cast<LPARAM>(&invalid_screen_rect); 674 LPARAM lparam = reinterpret_cast<LPARAM>(&invalid_screen_rect);
684 EnumChildWindows(m_hWnd, EnumChildProc, lparam); 675 EnumChildWindows(m_hWnd, EnumChildProc, lparam);
685 } 676 }
686 677
687 void RenderWidgetHostViewWin::DrawResizeCorner(const gfx::Rect& paint_rect,
688 HDC dc) {
689 gfx::Rect resize_corner_rect =
690 render_widget_host_->GetRootWindowResizerRect();
691 if (!paint_rect.Intersect(resize_corner_rect).IsEmpty()) {
692 SkBitmap* bitmap = ResourceBundle::GetSharedInstance().
693 GetBitmapNamed(IDR_TEXTAREA_RESIZER);
694 gfx::CanvasSkia canvas(bitmap->width(), bitmap->height(), false);
695 canvas.getDevice()->accessBitmap(true).eraseARGB(0, 0, 0, 0);
696 int x = resize_corner_rect.x() + resize_corner_rect.width() -
697 bitmap->width();
698 canvas.save();
699 if (base::i18n::IsRTL()) {
700 canvas.TranslateInt(bitmap->width(), 0);
701 canvas.ScaleInt(-1, 1);
702 x = 0;
703 }
704 canvas.DrawBitmapInt(*bitmap, 0, 0);
705 canvas.getTopPlatformDevice().drawToHDC(dc, x,
706 resize_corner_rect.y() + resize_corner_rect.height() -
707 bitmap->height(), NULL);
708 canvas.restore();
709 }
710 }
711
712 void RenderWidgetHostViewWin::DidUpdateBackingStore( 678 void RenderWidgetHostViewWin::DidUpdateBackingStore(
713 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, 679 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy,
714 const std::vector<gfx::Rect>& copy_rects) { 680 const std::vector<gfx::Rect>& copy_rects) {
715 if (is_hidden_) 681 if (is_hidden_)
716 return; 682 return;
717 683
718 // Schedule invalidations first so that the ScrollWindowEx call is closer to 684 // Schedule invalidations first so that the ScrollWindowEx call is closer to
719 // Redraw. That minimizes chances of "flicker" resulting if the screen 685 // Redraw. That minimizes chances of "flicker" resulting if the screen
720 // refreshes before we have a chance to paint the exposed area. Somewhat 686 // refreshes before we have a chance to paint the exposed area. Somewhat
721 // surprisingly, this ordering matters. 687 // surprisingly, this ordering matters.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 // Blit only the damaged regions from the backing store. 884 // Blit only the damaged regions from the backing store.
919 DWORD data_size = GetRegionData(damage_region, 0, NULL); 885 DWORD data_size = GetRegionData(damage_region, 0, NULL);
920 scoped_array<char> region_data_buf(new char[data_size]); 886 scoped_array<char> region_data_buf(new char[data_size]);
921 RGNDATA* region_data = reinterpret_cast<RGNDATA*>(region_data_buf.get()); 887 RGNDATA* region_data = reinterpret_cast<RGNDATA*>(region_data_buf.get());
922 GetRegionData(damage_region, data_size, region_data); 888 GetRegionData(damage_region, data_size, region_data);
923 889
924 RECT* region_rects = reinterpret_cast<RECT*>(region_data->Buffer); 890 RECT* region_rects = reinterpret_cast<RECT*>(region_data->Buffer);
925 for (DWORD i = 0; i < region_data->rdh.nCount; ++i) { 891 for (DWORD i = 0; i < region_data->rdh.nCount; ++i) {
926 gfx::Rect paint_rect = bitmap_rect.Intersect(gfx::Rect(region_rects[i])); 892 gfx::Rect paint_rect = bitmap_rect.Intersect(gfx::Rect(region_rects[i]));
927 if (!paint_rect.IsEmpty()) { 893 if (!paint_rect.IsEmpty()) {
928 DrawResizeCorner(paint_rect, backing_store->hdc());
929 if (visually_deemphasized_) { 894 if (visually_deemphasized_) {
930 DrawDeemphasized(paint_rect, backing_store->hdc(), paint_dc.m_hDC); 895 DrawDeemphasized(paint_rect, backing_store->hdc(), paint_dc.m_hDC);
931 } else { 896 } else {
932 BitBlt(paint_dc.m_hDC, 897 BitBlt(paint_dc.m_hDC,
933 paint_rect.x(), 898 paint_rect.x(),
934 paint_rect.y(), 899 paint_rect.y(),
935 paint_rect.width(), 900 paint_rect.width(),
936 paint_rect.height(), 901 paint_rect.height(),
937 backing_store->hdc(), 902 backing_store->hdc(),
938 paint_rect.x(), 903 paint_rect.x(),
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 // TabContents first in the case of popups. If we do, we would need to 1211 // TabContents first in the case of popups. If we do, we would need to
1247 // convert the click from the popup window coordinates to the TabContents' 1212 // convert the click from the popup window coordinates to the TabContents'
1248 // window coordinates. For now we don't forward the message in that case to 1213 // window coordinates. For now we don't forward the message in that case to
1249 // address bug #907474. 1214 // address bug #907474.
1250 // Note: GetParent() on popup windows returns the top window and not the 1215 // Note: GetParent() on popup windows returns the top window and not the
1251 // parent the window was created with (the parent and the owner of the popup 1216 // parent the window was created with (the parent and the owner of the popup
1252 // is the first non-child view of the view that was specified to the create 1217 // is the first non-child view of the view that was specified to the create
1253 // call). So the TabContents window would have to be specified to the 1218 // call). So the TabContents window would have to be specified to the
1254 // RenderViewHostHWND as there is no way to retrieve it from the HWND. 1219 // RenderViewHostHWND as there is no way to retrieve it from the HWND.
1255 if (!close_on_deactivate_) { // Don't forward if the container is a popup. 1220 if (!close_on_deactivate_) { // Don't forward if the container is a popup.
1256 if (message == WM_LBUTTONDOWN) {
1257 // If we get clicked on, where the resize corner is drawn, we delegate the
1258 // message to the root window, with the proper HTBOTTOMXXX wparam so that
1259 // Windows can take care of the resizing for us.
1260 if (render_widget_host_ &&
1261 render_widget_host_->GetRootWindowResizerRect().
1262 Contains(GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam))) {
1263 WPARAM wparam = HTBOTTOMRIGHT;
1264 if (base::i18n::IsRTL())
1265 wparam = HTBOTTOMLEFT;
1266 HWND root_hwnd = ::GetAncestor(m_hWnd, GA_ROOT);
1267 if (SendMessage(root_hwnd, WM_NCLBUTTONDOWN, wparam, lparam) == 0)
1268 return 0;
1269 }
1270 }
1271 switch (message) { 1221 switch (message) {
1272 case WM_LBUTTONDOWN: 1222 case WM_LBUTTONDOWN:
1273 case WM_MBUTTONDOWN: 1223 case WM_MBUTTONDOWN:
1274 case WM_RBUTTONDOWN: 1224 case WM_RBUTTONDOWN:
1275 // Finish the ongoing composition whenever a mouse click happens. 1225 // Finish the ongoing composition whenever a mouse click happens.
1276 // It matches IE's behavior. 1226 // It matches IE's behavior.
1277 ime_input_.CleanupComposition(m_hWnd); 1227 ime_input_.CleanupComposition(m_hWnd);
1278 // Fall through. 1228 // Fall through.
1279 case WM_MOUSEMOVE: 1229 case WM_MOUSEMOVE:
1280 case WM_MOUSELEAVE: { 1230 case WM_MOUSELEAVE: {
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( 1636 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView(
1687 gfx::NativeView native_view) { 1637 gfx::NativeView native_view) {
1688 if (::IsWindow(native_view)) { 1638 if (::IsWindow(native_view)) {
1689 HANDLE raw_render_host_view = ::GetProp(native_view, 1639 HANDLE raw_render_host_view = ::GetProp(native_view,
1690 kRenderWidgetHostViewKey); 1640 kRenderWidgetHostViewKey);
1691 if (raw_render_host_view) 1641 if (raw_render_host_view)
1692 return reinterpret_cast<RenderWidgetHostView*>(raw_render_host_view); 1642 return reinterpret_cast<RenderWidgetHostView*>(raw_render_host_view);
1693 } 1643 }
1694 return NULL; 1644 return NULL;
1695 } 1645 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_win.h ('k') | chrome/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698