| 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/views/widget_win.h" | 5 #include "chrome/views/widget_win.h" |
| 6 | 6 |
| 7 #include "base/gfx/native_theme.h" | 7 #include "base/gfx/native_theme.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/win_util.h" | 9 #include "base/win_util.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 /////////////////////////////////////////////////////////////////////////////// | 113 /////////////////////////////////////////////////////////////////////////////// |
| 114 // WidgetWin, public | 114 // WidgetWin, public |
| 115 | 115 |
| 116 WidgetWin::WidgetWin() | 116 WidgetWin::WidgetWin() |
| 117 : active_mouse_tracking_flags_(0), | 117 : active_mouse_tracking_flags_(0), |
| 118 has_capture_(false), | 118 has_capture_(false), |
| 119 current_action_(FA_NONE), | 119 current_action_(FA_NONE), |
| 120 toplevel_(false), | 120 toplevel_(false), |
| 121 window_style_(0), | 121 window_style_(0), |
| 122 window_ex_style_(kWindowDefaultExStyle), | 122 window_ex_style_(kWindowDefaultExStyle), |
| 123 layered_(false), | 123 use_layered_buffer_(true), |
| 124 layered_alpha_(255), | 124 layered_alpha_(255), |
| 125 delete_on_destroy_(true), | 125 delete_on_destroy_(true), |
| 126 can_update_layered_window_(true), | 126 can_update_layered_window_(true), |
| 127 last_mouse_event_was_move_(false), | 127 last_mouse_event_was_move_(false), |
| 128 is_mouse_down_(false), | 128 is_mouse_down_(false), |
| 129 class_style_(CS_DBLCLKS), | 129 class_style_(CS_DBLCLKS), |
| 130 hwnd_(NULL), | 130 hwnd_(NULL), |
| 131 close_widget_factory_(this) { | 131 close_widget_factory_(this) { |
| 132 } | 132 } |
| 133 | 133 |
| 134 WidgetWin::~WidgetWin() { | 134 WidgetWin::~WidgetWin() { |
| 135 MessageLoopForUI::current()->RemoveObserver(this); | 135 MessageLoopForUI::current()->RemoveObserver(this); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void WidgetWin::Init(HWND parent, const gfx::Rect& bounds, | 138 void WidgetWin::Init(HWND parent, const gfx::Rect& bounds, |
| 139 bool has_own_focus_manager) { | 139 bool has_own_focus_manager) { |
| 140 toplevel_ = parent == NULL; | 140 toplevel_ = parent == NULL; |
| 141 | 141 |
| 142 if (window_style_ == 0) | 142 if (window_style_ == 0) |
| 143 window_style_ = toplevel_ ? kWindowDefaultStyle : kWindowDefaultChildStyle; | 143 window_style_ = toplevel_ ? kWindowDefaultStyle : kWindowDefaultChildStyle; |
| 144 | 144 |
| 145 // See if the style has been overridden. | 145 // See if the style has been overridden. |
| 146 opaque_ = !(window_ex_style_ & WS_EX_TRANSPARENT); | 146 opaque_ = !(window_ex_style_ & WS_EX_TRANSPARENT); |
| 147 layered_ = !!(window_ex_style_ & WS_EX_LAYERED); | 147 use_layered_buffer_ = (use_layered_buffer_ && |
| 148 !!(window_ex_style_ & WS_EX_LAYERED)); |
| 148 | 149 |
| 149 // Force creation of the RootView if it hasn't been created yet. | 150 // Force creation of the RootView if it hasn't been created yet. |
| 150 GetRootView(); | 151 GetRootView(); |
| 151 | 152 |
| 152 // Ensures the parent we have been passed is valid, otherwise CreateWindowEx | 153 // Ensures the parent we have been passed is valid, otherwise CreateWindowEx |
| 153 // will fail. | 154 // will fail. |
| 154 if (parent && !::IsWindow(parent)) { | 155 if (parent && !::IsWindow(parent)) { |
| 155 NOTREACHED() << "invalid parent window specified."; | 156 NOTREACHED() << "invalid parent window specified."; |
| 156 parent = NULL; | 157 parent = NULL; |
| 157 } | 158 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 flags |= SWP_NOACTIVATE; | 240 flags |= SWP_NOACTIVATE; |
| 240 } | 241 } |
| 241 SetWindowPos(HWND_NOTOPMOST, 0, 0, 0, 0, flags); | 242 SetWindowPos(HWND_NOTOPMOST, 0, 0, 0, 0, flags); |
| 242 } | 243 } |
| 243 | 244 |
| 244 HWND WidgetWin::GetHWND() const { | 245 HWND WidgetWin::GetHWND() const { |
| 245 return hwnd_; | 246 return hwnd_; |
| 246 } | 247 } |
| 247 | 248 |
| 248 void WidgetWin::PaintNow(const gfx::Rect& update_rect) { | 249 void WidgetWin::PaintNow(const gfx::Rect& update_rect) { |
| 249 if (layered_) { | 250 if (use_layered_buffer_) { |
| 250 PaintLayeredWindow(); | 251 PaintLayeredWindow(); |
| 251 } else if (root_view_->NeedsPainting(false) && IsWindow()) { | 252 } else if (root_view_->NeedsPainting(false) && IsWindow()) { |
| 252 if (!opaque_ && GetParent()) { | 253 if (!opaque_ && GetParent()) { |
| 253 // We're transparent. Need to force painting to occur from our parent. | 254 // We're transparent. Need to force painting to occur from our parent. |
| 254 CRect parent_update_rect = update_rect.ToRECT(); | 255 CRect parent_update_rect = update_rect.ToRECT(); |
| 255 POINT location_in_parent = { 0, 0 }; | 256 POINT location_in_parent = { 0, 0 }; |
| 256 ClientToScreen(hwnd_, &location_in_parent); | 257 ClientToScreen(hwnd_, &location_in_parent); |
| 257 ::ScreenToClient(GetParent(), &location_in_parent); | 258 ::ScreenToClient(GetParent(), &location_in_parent); |
| 258 parent_update_rect.OffsetRect(location_in_parent); | 259 parent_update_rect.OffsetRect(location_in_parent); |
| 259 ::RedrawWindow(GetParent(), parent_update_rect, NULL, | 260 ::RedrawWindow(GetParent(), parent_update_rect, NULL, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 296 } |
| 296 | 297 |
| 297 | 298 |
| 298 void WidgetWin::SetLayeredAlpha(BYTE layered_alpha) { | 299 void WidgetWin::SetLayeredAlpha(BYTE layered_alpha) { |
| 299 layered_alpha_ = layered_alpha; | 300 layered_alpha_ = layered_alpha; |
| 300 | 301 |
| 301 // if (hwnd_) | 302 // if (hwnd_) |
| 302 // UpdateWindowFromContents(contents_->getTopPlatformDevice().getBitmapDC()); | 303 // UpdateWindowFromContents(contents_->getTopPlatformDevice().getBitmapDC()); |
| 303 } | 304 } |
| 304 | 305 |
| 306 void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { |
| 307 if (use_layered_buffer_ == use_layered_buffer) |
| 308 return; |
| 309 |
| 310 use_layered_buffer_ = use_layered_buffer; |
| 311 if (!hwnd_) |
| 312 return; |
| 313 |
| 314 if (use_layered_buffer_) { |
| 315 // Force creation of the buffer at the right size. |
| 316 RECT wr; |
| 317 GetWindowRect(&wr); |
| 318 ChangeSize(0, CSize(wr.right - wr.left, wr.bottom - wr.top)); |
| 319 } else { |
| 320 contents_.reset(NULL); |
| 321 } |
| 322 } |
| 323 |
| 305 static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) { | 324 static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) { |
| 306 RootView* root_view = | 325 RootView* root_view = |
| 307 reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); | 326 reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); |
| 308 if (root_view) { | 327 if (root_view) { |
| 309 *reinterpret_cast<RootView**>(l_param) = root_view; | 328 *reinterpret_cast<RootView**>(l_param) = root_view; |
| 310 return FALSE; // Stop enumerating. | 329 return FALSE; // Stop enumerating. |
| 311 } | 330 } |
| 312 return TRUE; // Keep enumerating. | 331 return TRUE; // Keep enumerating. |
| 313 } | 332 } |
| 314 | 333 |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 new_window_rect.x(), | 811 new_window_rect.x(), |
| 793 new_window_rect.y(), | 812 new_window_rect.y(), |
| 794 new_window_rect.width(), | 813 new_window_rect.width(), |
| 795 new_window_rect.height(), | 814 new_window_rect.height(), |
| 796 SWP_NOACTIVATE | SWP_NOZORDER); | 815 SWP_NOACTIVATE | SWP_NOZORDER); |
| 797 } | 816 } |
| 798 } | 817 } |
| 799 | 818 |
| 800 void WidgetWin::ChangeSize(UINT size_param, const CSize& size) { | 819 void WidgetWin::ChangeSize(UINT size_param, const CSize& size) { |
| 801 CRect rect; | 820 CRect rect; |
| 802 if (layered_) { | 821 if (use_layered_buffer_) { |
| 803 GetWindowRect(&rect); | 822 GetWindowRect(&rect); |
| 804 SizeContents(rect); | 823 SizeContents(rect); |
| 805 } else { | 824 } else { |
| 806 GetClientRect(&rect); | 825 GetClientRect(&rect); |
| 807 } | 826 } |
| 808 | 827 |
| 809 // Resizing changes the size of the view hierarchy and thus forces a | 828 // Resizing changes the size of the view hierarchy and thus forces a |
| 810 // complete relayout. | 829 // complete relayout. |
| 811 root_view_->SetBounds(0, 0, rect.Width(), rect.Height()); | 830 root_view_->SetBounds(0, 0, rect.Width(), rect.Height()); |
| 812 root_view_->Layout(); | 831 root_view_->Layout(); |
| 813 root_view_->SchedulePaint(); | 832 root_view_->SchedulePaint(); |
| 814 | 833 |
| 815 if (layered_) | 834 if (use_layered_buffer_) |
| 816 PaintNow(gfx::Rect(rect)); | 835 PaintNow(gfx::Rect(rect)); |
| 817 } | 836 } |
| 818 | 837 |
| 819 RootView* WidgetWin::CreateRootView() { | 838 RootView* WidgetWin::CreateRootView() { |
| 820 return new RootView(this); | 839 return new RootView(this); |
| 821 } | 840 } |
| 822 | 841 |
| 823 /////////////////////////////////////////////////////////////////////////////// | 842 /////////////////////////////////////////////////////////////////////////////// |
| 824 // WidgetWin, private: | 843 // WidgetWin, private: |
| 825 | 844 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 837 gfx::Rect dirty_rect = root_view_->GetScheduledPaintRect(); | 856 gfx::Rect dirty_rect = root_view_->GetScheduledPaintRect(); |
| 838 contents_->ClipRectInt(dirty_rect.x(), dirty_rect.y(), dirty_rect.width(), | 857 contents_->ClipRectInt(dirty_rect.x(), dirty_rect.y(), dirty_rect.width(), |
| 839 dirty_rect.height()); | 858 dirty_rect.height()); |
| 840 root_view_->ProcessPaint(contents_.get()); | 859 root_view_->ProcessPaint(contents_.get()); |
| 841 contents_->restore(); | 860 contents_->restore(); |
| 842 | 861 |
| 843 UpdateWindowFromContents(contents_->getTopPlatformDevice().getBitmapDC()); | 862 UpdateWindowFromContents(contents_->getTopPlatformDevice().getBitmapDC()); |
| 844 } | 863 } |
| 845 | 864 |
| 846 void WidgetWin::UpdateWindowFromContents(HDC dib_dc) { | 865 void WidgetWin::UpdateWindowFromContents(HDC dib_dc) { |
| 847 DCHECK(layered_); | 866 DCHECK(use_layered_buffer_); |
| 848 if (can_update_layered_window_) { | 867 if (can_update_layered_window_) { |
| 849 CRect wr; | 868 CRect wr; |
| 850 GetWindowRect(&wr); | 869 GetWindowRect(&wr); |
| 851 CSize size(wr.right - wr.left, wr.bottom - wr.top); | 870 CSize size(wr.right - wr.left, wr.bottom - wr.top); |
| 852 CPoint zero_origin(0, 0); | 871 CPoint zero_origin(0, 0); |
| 853 CPoint window_position = wr.TopLeft(); | 872 CPoint window_position = wr.TopLeft(); |
| 854 | 873 |
| 855 BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; | 874 BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; |
| 856 ::UpdateLayeredWindow( | 875 ::UpdateLayeredWindow( |
| 857 hwnd_, NULL, &window_position, &size, dib_dc, &zero_origin, | 876 hwnd_, NULL, &window_position, &size, dib_dc, &zero_origin, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 result = DefWindowProc(window, message, w_param, l_param); | 933 result = DefWindowProc(window, message, w_param, l_param); |
| 915 if (message == WM_NCDESTROY) { | 934 if (message == WM_NCDESTROY) { |
| 916 widget->hwnd_ = NULL; | 935 widget->hwnd_ = NULL; |
| 917 widget->OnFinalMessage(window); | 936 widget->OnFinalMessage(window); |
| 918 } | 937 } |
| 919 return result; | 938 return result; |
| 920 } | 939 } |
| 921 | 940 |
| 922 } // namespace views | 941 } // namespace views |
| 923 | 942 |
| OLD | NEW |