| 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 "views/widget/widget_win.h" | 5 #include "views/widget/widget_win.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/gfx/path.h" | 8 #include "app/gfx/path.h" |
| 9 #include "app/win_util.h" | 9 #include "app/win_util.h" |
| 10 #include "base/gfx/native_theme.h" | 10 #include "base/gfx/native_theme.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 is_mouse_down_(false), | 147 is_mouse_down_(false), |
| 148 is_window_(false), | 148 is_window_(false), |
| 149 class_style_(CS_DBLCLKS), | 149 class_style_(CS_DBLCLKS), |
| 150 hwnd_(NULL) { | 150 hwnd_(NULL) { |
| 151 } | 151 } |
| 152 | 152 |
| 153 WidgetWin::~WidgetWin() { | 153 WidgetWin::~WidgetWin() { |
| 154 MessageLoopForUI::current()->RemoveObserver(this); | 154 MessageLoopForUI::current()->RemoveObserver(this); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void WidgetWin::Init(HWND parent, const gfx::Rect& bounds, | 157 void WidgetWin::Init(HWND parent, const gfx::Rect& bounds) { |
| 158 bool has_own_focus_manager) { | |
| 159 if (window_style_ == 0) | 158 if (window_style_ == 0) |
| 160 window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle; | 159 window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle; |
| 161 | 160 |
| 162 // See if the style has been overridden. | 161 // See if the style has been overridden. |
| 163 opaque_ = !(window_ex_style_ & WS_EX_TRANSPARENT); | 162 opaque_ = !(window_ex_style_ & WS_EX_TRANSPARENT); |
| 164 use_layered_buffer_ = (use_layered_buffer_ && | 163 use_layered_buffer_ = (use_layered_buffer_ && |
| 165 !!(window_ex_style_ & WS_EX_LAYERED)); | 164 !!(window_ex_style_ & WS_EX_LAYERED)); |
| 166 | 165 |
| 167 // Force creation of the RootView if it hasn't been created yet. | 166 // Force creation of the RootView if it hasn't been created yet. |
| 168 GetRootView(); | 167 GetRootView(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 180 window_style_, bounds.x(), bounds.y(), bounds.width(), | 179 window_style_, bounds.x(), bounds.y(), bounds.width(), |
| 181 bounds.height(), parent, NULL, NULL, this); | 180 bounds.height(), parent, NULL, NULL, this); |
| 182 DCHECK(hwnd_); | 181 DCHECK(hwnd_); |
| 183 SetWindowSupportsRerouteMouseWheel(hwnd_); | 182 SetWindowSupportsRerouteMouseWheel(hwnd_); |
| 184 | 183 |
| 185 // The window procedure should have set the data for us. | 184 // The window procedure should have set the data for us. |
| 186 DCHECK(win_util::GetWindowUserData(hwnd_) == this); | 185 DCHECK(win_util::GetWindowUserData(hwnd_) == this); |
| 187 | 186 |
| 188 root_view_->OnWidgetCreated(); | 187 root_view_->OnWidgetCreated(); |
| 189 | 188 |
| 190 if (has_own_focus_manager) { | 189 if ((window_style_ & WS_CHILD) == 0) { |
| 191 FocusManager::CreateFocusManager(hwnd_, GetRootView()); | 190 // Top-level widgets get a FocusManager. |
| 191 focus_manager_.reset(new FocusManager(this)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 // Sets the RootView as a property, so the automation can introspect windows. | 194 // Sets the RootView as a property, so the automation can introspect windows. |
| 195 SetRootViewForHWND(hwnd_, root_view_.get()); | 195 SetRootViewForHWND(hwnd_, root_view_.get()); |
| 196 | 196 |
| 197 MessageLoopForUI::current()->AddObserver(this); | 197 MessageLoopForUI::current()->AddObserver(this); |
| 198 | 198 |
| 199 // Windows special DWM window frame requires a special tooltip manager so | 199 // Windows special DWM window frame requires a special tooltip manager so |
| 200 // that window controls in Chrome windows don't flicker when you move your | 200 // that window controls in Chrome windows don't flicker when you move your |
| 201 // mouse over them. See comment in aero_tooltip_manager.h. | 201 // mouse over them. See comment in aero_tooltip_manager.h. |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } | 412 } |
| 413 | 413 |
| 414 Window* WidgetWin::GetWindow() { | 414 Window* WidgetWin::GetWindow() { |
| 415 return GetWindowImpl(hwnd_); | 415 return GetWindowImpl(hwnd_); |
| 416 } | 416 } |
| 417 | 417 |
| 418 const Window* WidgetWin::GetWindow() const { | 418 const Window* WidgetWin::GetWindow() const { |
| 419 return GetWindowImpl(hwnd_); | 419 return GetWindowImpl(hwnd_); |
| 420 } | 420 } |
| 421 | 421 |
| 422 FocusManager* WidgetWin::GetFocusManager() { |
| 423 if (focus_manager_.get()) |
| 424 return focus_manager_.get(); |
| 425 |
| 426 HWND root = ::GetAncestor(hwnd_, GA_ROOT); |
| 427 if (!root) |
| 428 return NULL; |
| 429 |
| 430 WidgetWin* widget = GetWidget(root); |
| 431 return widget ? widget->focus_manager_.get() : NULL; |
| 432 } |
| 433 |
| 422 void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { | 434 void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { |
| 423 if (use_layered_buffer_ == use_layered_buffer) | 435 if (use_layered_buffer_ == use_layered_buffer) |
| 424 return; | 436 return; |
| 425 | 437 |
| 426 use_layered_buffer_ = use_layered_buffer; | 438 use_layered_buffer_ = use_layered_buffer; |
| 427 if (!hwnd_) | 439 if (!hwnd_) |
| 428 return; | 440 return; |
| 429 | 441 |
| 430 if (use_layered_buffer_) { | 442 if (use_layered_buffer_) { |
| 431 // Force creation of the buffer at the right size. | 443 // Force creation of the buffer at the right size. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 453 reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); | 465 reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); |
| 454 if (root_view) | 466 if (root_view) |
| 455 return root_view; | 467 return root_view; |
| 456 | 468 |
| 457 // Enumerate all children and check if they have a RootView. | 469 // Enumerate all children and check if they have a RootView. |
| 458 EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast<LPARAM>(&root_view)); | 470 EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast<LPARAM>(&root_view)); |
| 459 | 471 |
| 460 return root_view; | 472 return root_view; |
| 461 } | 473 } |
| 462 | 474 |
| 463 /////////////////////////////////////////////////////////////////////////////// | 475 // static |
| 476 WidgetWin* WidgetWin::GetWidget(HWND hwnd) { |
| 477 return reinterpret_cast<WidgetWin*>(win_util::GetWindowUserData(hwnd)); |
| 478 } |
| 479 |
| 480 //////////////////////////////////////////////////////////////////////////////// |
| 464 // MessageLoop::Observer | 481 // MessageLoop::Observer |
| 465 | 482 |
| 466 void WidgetWin::WillProcessMessage(const MSG& msg) { | 483 void WidgetWin::WillProcessMessage(const MSG& msg) { |
| 467 } | 484 } |
| 468 | 485 |
| 469 void WidgetWin::DidProcessMessage(const MSG& msg) { | 486 void WidgetWin::DidProcessMessage(const MSG& msg) { |
| 470 if (root_view_->NeedsPainting(true)) { | 487 if (root_view_->NeedsPainting(true)) { |
| 471 PaintNow(root_view_->GetScheduledPaintRect()); | 488 PaintNow(root_view_->GetScheduledPaintRect()); |
| 472 } | 489 } |
| 473 } | 490 } |
| 474 | 491 |
| 475 /////////////////////////////////////////////////////////////////////////////// | 492 //////////////////////////////////////////////////////////////////////////////// |
| 476 // FocusTraversable | 493 // FocusTraversable |
| 477 | 494 |
| 478 View* WidgetWin::FindNextFocusableView( | 495 View* WidgetWin::FindNextFocusableView( |
| 479 View* starting_view, bool reverse, Direction direction, | 496 View* starting_view, bool reverse, Direction direction, |
| 480 bool check_starting_view, FocusTraversable** focus_traversable, | 497 bool check_starting_view, FocusTraversable** focus_traversable, |
| 481 View** focus_traversable_view) { | 498 View** focus_traversable_view) { |
| 482 return root_view_->FindNextFocusableView(starting_view, | 499 return root_view_->FindNextFocusableView(starting_view, |
| 483 reverse, | 500 reverse, |
| 484 direction, | 501 direction, |
| 485 check_starting_view, | 502 check_starting_view, |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 | 1049 |
| 1033 // First allow messages sent by child controls to be processed directly by | 1050 // First allow messages sent by child controls to be processed directly by |
| 1034 // their associated views. If such a view is present, it will handle the | 1051 // their associated views. If such a view is present, it will handle the |
| 1035 // message *instead of* this WidgetWin. | 1052 // message *instead of* this WidgetWin. |
| 1036 if (ProcessNativeControlMessage(message, w_param, l_param, &result)) | 1053 if (ProcessNativeControlMessage(message, w_param, l_param, &result)) |
| 1037 return result; | 1054 return result; |
| 1038 | 1055 |
| 1039 // Otherwise we handle everything else. | 1056 // Otherwise we handle everything else. |
| 1040 if (!widget->ProcessWindowMessage(window, message, w_param, l_param, result)) | 1057 if (!widget->ProcessWindowMessage(window, message, w_param, l_param, result)) |
| 1041 result = DefWindowProc(window, message, w_param, l_param); | 1058 result = DefWindowProc(window, message, w_param, l_param); |
| 1042 if (message == WM_NCDESTROY) { | 1059 if (message == WM_NCDESTROY) |
| 1043 widget->hwnd_ = NULL; | |
| 1044 widget->OnFinalMessage(window); | 1060 widget->OnFinalMessage(window); |
| 1045 } | |
| 1046 if (message == WM_ACTIVATE) | 1061 if (message == WM_ACTIVATE) |
| 1047 PostProcessActivateMessage(widget, LOWORD(w_param)); | 1062 PostProcessActivateMessage(widget, LOWORD(w_param)); |
| 1048 return result; | 1063 return result; |
| 1049 } | 1064 } |
| 1050 | 1065 |
| 1051 // static | 1066 // static |
| 1052 void WidgetWin::PostProcessActivateMessage(WidgetWin* widget, | 1067 void WidgetWin::PostProcessActivateMessage(WidgetWin* widget, |
| 1053 int activation_state) { | 1068 int activation_state) { |
| 1054 FocusManager* focus_manager = | 1069 if (!widget->focus_manager_.get()) { |
| 1055 FocusManager::GetFocusManager(widget->GetNativeView()); | |
| 1056 if (!focus_manager) { | |
| 1057 NOTREACHED(); | 1070 NOTREACHED(); |
| 1058 return; | 1071 return; |
| 1059 } | 1072 } |
| 1060 if (WA_INACTIVE == activation_state) { | 1073 if (WA_INACTIVE == activation_state) { |
| 1061 focus_manager->StoreFocusedView(); | 1074 widget->focus_manager_->StoreFocusedView(); |
| 1062 } else { | 1075 } else { |
| 1063 // We must restore the focus after the message has been DefProc'ed as it | 1076 // We must restore the focus after the message has been DefProc'ed as it |
| 1064 // does set the focus to the last focused HWND. | 1077 // does set the focus to the last focused HWND. |
| 1065 focus_manager->RestoreFocusedView(); | 1078 widget->focus_manager_->RestoreFocusedView(); |
| 1066 } | 1079 } |
| 1067 } | 1080 } |
| 1068 } // namespace views | 1081 } // namespace views |
| OLD | NEW |