| 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/widget_win.h" | 5 #include "chrome/views/widget/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" |
| 11 #include "chrome/common/gfx/chrome_canvas.h" | 11 #include "chrome/common/gfx/chrome_canvas.h" |
| 12 #include "chrome/common/notification_service.h" | 12 #include "chrome/common/notification_service.h" |
| 13 #include "chrome/common/win_util.h" | 13 #include "chrome/common/win_util.h" |
| 14 #include "chrome/views/accessibility/view_accessibility.h" | 14 #include "chrome/views/accessibility/view_accessibility.h" |
| 15 #include "chrome/views/controls/native_control_win.h" | 15 #include "chrome/views/controls/native_control_win.h" |
| 16 #include "chrome/views/fill_layout.h" | 16 #include "chrome/views/fill_layout.h" |
| 17 #include "chrome/views/focus/focus_util_win.h" | 17 #include "chrome/views/focus/focus_util_win.h" |
| 18 #include "chrome/views/widget/aero_tooltip_manager.h" | 18 #include "chrome/views/widget/aero_tooltip_manager.h" |
| 19 #include "chrome/views/widget/hwnd_notification_source.h" | 19 #include "chrome/views/widget/hwnd_notification_source.h" |
| 20 #include "chrome/views/widget/root_view.h" | 20 #include "chrome/views/widget/root_view.h" |
| 21 #include "chrome/views/window/window_win.h" |
| 21 | 22 |
| 22 namespace views { | 23 namespace views { |
| 23 | 24 |
| 24 static const DWORD kWindowDefaultChildStyle = | 25 static const DWORD kWindowDefaultChildStyle = |
| 25 WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; | 26 WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; |
| 26 static const DWORD kWindowDefaultStyle = WS_OVERLAPPEDWINDOW; | 27 static const DWORD kWindowDefaultStyle = WS_OVERLAPPEDWINDOW; |
| 27 static const DWORD kWindowDefaultExStyle = 0; | 28 static const DWORD kWindowDefaultExStyle = 0; |
| 28 | 29 |
| 29 // Property used to link the HWND to its RootView. | 30 // Property used to link the HWND to its RootView. |
| 30 static const wchar_t* const kRootViewWindowProperty = L"__ROOT_VIEW__"; | 31 static const wchar_t* const kRootViewWindowProperty = L"__ROOT_VIEW__"; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 has_capture_(false), | 139 has_capture_(false), |
| 139 current_action_(FA_NONE), | 140 current_action_(FA_NONE), |
| 140 window_style_(0), | 141 window_style_(0), |
| 141 window_ex_style_(kWindowDefaultExStyle), | 142 window_ex_style_(kWindowDefaultExStyle), |
| 142 use_layered_buffer_(true), | 143 use_layered_buffer_(true), |
| 143 layered_alpha_(255), | 144 layered_alpha_(255), |
| 144 delete_on_destroy_(true), | 145 delete_on_destroy_(true), |
| 145 can_update_layered_window_(true), | 146 can_update_layered_window_(true), |
| 146 last_mouse_event_was_move_(false), | 147 last_mouse_event_was_move_(false), |
| 147 is_mouse_down_(false), | 148 is_mouse_down_(false), |
| 149 is_window_(false), |
| 148 class_style_(CS_DBLCLKS), | 150 class_style_(CS_DBLCLKS), |
| 149 hwnd_(NULL) { | 151 hwnd_(NULL) { |
| 150 } | 152 } |
| 151 | 153 |
| 152 WidgetWin::~WidgetWin() { | 154 WidgetWin::~WidgetWin() { |
| 153 MessageLoopForUI::current()->RemoveObserver(this); | 155 MessageLoopForUI::current()->RemoveObserver(this); |
| 154 } | 156 } |
| 155 | 157 |
| 156 void WidgetWin::Init(HWND parent, const gfx::Rect& bounds, | 158 void WidgetWin::Init(HWND parent, const gfx::Rect& bounds, |
| 157 bool has_own_focus_manager) { | 159 bool has_own_focus_manager) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 return; | 247 return; |
| 246 } | 248 } |
| 247 | 249 |
| 248 GetClientRect(&crect); | 250 GetClientRect(&crect); |
| 249 POINT p = {0, 0}; | 251 POINT p = {0, 0}; |
| 250 ::ClientToScreen(hwnd_, &p); | 252 ::ClientToScreen(hwnd_, &p); |
| 251 out->SetRect(crect.left + p.x, crect.top + p.y, | 253 out->SetRect(crect.left + p.x, crect.top + p.y, |
| 252 crect.Width(), crect.Height()); | 254 crect.Width(), crect.Height()); |
| 253 } | 255 } |
| 254 | 256 |
| 255 void WidgetWin::MoveToFront(bool should_activate) { | |
| 256 int flags = SWP_NOMOVE | SWP_NOSIZE; | |
| 257 if (!should_activate) { | |
| 258 flags |= SWP_NOACTIVATE; | |
| 259 } | |
| 260 | |
| 261 // Keep the window topmost if it was already topmost. | |
| 262 WINDOWINFO wi; | |
| 263 wi.cbSize = sizeof WINDOWINFO; | |
| 264 GetWindowInfo(GetNativeView(), &wi); | |
| 265 SetWindowPos((wi.dwExStyle & WS_EX_TOPMOST) ? HWND_TOPMOST : HWND_NOTOPMOST, | |
| 266 0, 0, 0, 0, flags); | |
| 267 } | |
| 268 | |
| 269 gfx::NativeView WidgetWin::GetNativeView() const { | 257 gfx::NativeView WidgetWin::GetNativeView() const { |
| 270 return hwnd_; | 258 return hwnd_; |
| 271 } | 259 } |
| 272 | 260 |
| 273 void WidgetWin::PaintNow(const gfx::Rect& update_rect) { | 261 void WidgetWin::PaintNow(const gfx::Rect& update_rect) { |
| 274 if (use_layered_buffer_) { | 262 if (use_layered_buffer_) { |
| 275 PaintLayeredWindow(); | 263 PaintLayeredWindow(); |
| 276 } else if (root_view_->NeedsPainting(false) && IsWindow()) { | 264 } else if (root_view_->NeedsPainting(false) && IsWindow()) { |
| 277 if (!opaque_ && GetParent()) { | 265 if (!opaque_ && GetParent()) { |
| 278 // We're transparent. Need to force painting to occur from our parent. | 266 // We're transparent. Need to force painting to occur from our parent. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 } | 300 } |
| 313 | 301 |
| 314 bool WidgetWin::IsActive() const { | 302 bool WidgetWin::IsActive() const { |
| 315 return win_util::IsWindowActive(GetNativeView()); | 303 return win_util::IsWindowActive(GetNativeView()); |
| 316 } | 304 } |
| 317 | 305 |
| 318 TooltipManager* WidgetWin::GetTooltipManager() { | 306 TooltipManager* WidgetWin::GetTooltipManager() { |
| 319 return tooltip_manager_.get(); | 307 return tooltip_manager_.get(); |
| 320 } | 308 } |
| 321 | 309 |
| 310 Window* WidgetWin::GetWindow() { |
| 311 return GetWindowImpl(hwnd_); |
| 312 } |
| 313 |
| 314 const Window* WidgetWin::GetWindow() const { |
| 315 return GetWindowImpl(hwnd_); |
| 316 } |
| 322 | 317 |
| 323 void WidgetWin::SetLayeredAlpha(BYTE layered_alpha) { | 318 void WidgetWin::SetLayeredAlpha(BYTE layered_alpha) { |
| 324 layered_alpha_ = layered_alpha; | 319 layered_alpha_ = layered_alpha; |
| 325 | 320 |
| 326 // if (hwnd_) | 321 // if (hwnd_) |
| 327 // UpdateWindowFromContents(contents_->getTopPlatformDevice().getBitmapDC()); | 322 // UpdateWindowFromContents(contents_->getTopPlatformDevice().getBitmapDC()); |
| 328 } | 323 } |
| 329 | 324 |
| 330 void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { | 325 void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { |
| 331 if (use_layered_buffer_ == use_layered_buffer) | 326 if (use_layered_buffer_ == use_layered_buffer) |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 PaintNow(gfx::Rect(rect)); | 838 PaintNow(gfx::Rect(rect)); |
| 844 } | 839 } |
| 845 | 840 |
| 846 RootView* WidgetWin::CreateRootView() { | 841 RootView* WidgetWin::CreateRootView() { |
| 847 return new RootView(this); | 842 return new RootView(this); |
| 848 } | 843 } |
| 849 | 844 |
| 850 /////////////////////////////////////////////////////////////////////////////// | 845 /////////////////////////////////////////////////////////////////////////////// |
| 851 // WidgetWin, private: | 846 // WidgetWin, private: |
| 852 | 847 |
| 848 // static |
| 849 Window* WidgetWin::GetWindowImpl(HWND hwnd) { |
| 850 // NOTE: we can't use GetAncestor here as constrained windows are a Window, |
| 851 // but not a top level window. |
| 852 HWND parent = hwnd; |
| 853 while (parent) { |
| 854 WidgetWin* widget = |
| 855 reinterpret_cast<WidgetWin*>(win_util::GetWindowUserData(parent)); |
| 856 if (widget && widget->is_window_) |
| 857 return static_cast<WindowWin*>(widget); |
| 858 parent = ::GetParent(parent); |
| 859 } |
| 860 return NULL; |
| 861 } |
| 862 |
| 853 void WidgetWin::SizeContents(const CRect& window_rect) { | 863 void WidgetWin::SizeContents(const CRect& window_rect) { |
| 854 contents_.reset(new ChromeCanvas(window_rect.Width(), | 864 contents_.reset(new ChromeCanvas(window_rect.Width(), |
| 855 window_rect.Height(), | 865 window_rect.Height(), |
| 856 false)); | 866 false)); |
| 857 } | 867 } |
| 858 | 868 |
| 859 void WidgetWin::PaintLayeredWindow() { | 869 void WidgetWin::PaintLayeredWindow() { |
| 860 // Painting monkeys with our cliprect, so we need to save it so that the | 870 // Painting monkeys with our cliprect, so we need to save it so that the |
| 861 // call to UpdateLayeredWindow updates the entire window, not just the | 871 // call to UpdateLayeredWindow updates the entire window, not just the |
| 862 // cliprect. | 872 // cliprect. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 result = DefWindowProc(window, message, w_param, l_param); | 998 result = DefWindowProc(window, message, w_param, l_param); |
| 989 if (message == WM_NCDESTROY) { | 999 if (message == WM_NCDESTROY) { |
| 990 TRACK_HWND_DESTRUCTION(window); | 1000 TRACK_HWND_DESTRUCTION(window); |
| 991 widget->hwnd_ = NULL; | 1001 widget->hwnd_ = NULL; |
| 992 widget->OnFinalMessage(window); | 1002 widget->OnFinalMessage(window); |
| 993 } | 1003 } |
| 994 return result; | 1004 return result; |
| 995 } | 1005 } |
| 996 | 1006 |
| 997 } // namespace views | 1007 } // namespace views |
| OLD | NEW |