| 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) { |
| 158 if (window_style_ == 0) | 159 if (window_style_ == 0) |
| 159 window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle; | 160 window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle; |
| 160 | 161 |
| 161 // See if the style has been overridden. | 162 // See if the style has been overridden. |
| 162 opaque_ = !(window_ex_style_ & WS_EX_TRANSPARENT); | 163 opaque_ = !(window_ex_style_ & WS_EX_TRANSPARENT); |
| 163 use_layered_buffer_ = (use_layered_buffer_ && | 164 use_layered_buffer_ = (use_layered_buffer_ && |
| 164 !!(window_ex_style_ & WS_EX_LAYERED)); | 165 !!(window_ex_style_ & WS_EX_LAYERED)); |
| 165 | 166 |
| 166 // Force creation of the RootView if it hasn't been created yet. | 167 // Force creation of the RootView if it hasn't been created yet. |
| 167 GetRootView(); | 168 GetRootView(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 179 window_style_, bounds.x(), bounds.y(), bounds.width(), | 180 window_style_, bounds.x(), bounds.y(), bounds.width(), |
| 180 bounds.height(), parent, NULL, NULL, this); | 181 bounds.height(), parent, NULL, NULL, this); |
| 181 DCHECK(hwnd_); | 182 DCHECK(hwnd_); |
| 182 SetWindowSupportsRerouteMouseWheel(hwnd_); | 183 SetWindowSupportsRerouteMouseWheel(hwnd_); |
| 183 | 184 |
| 184 // The window procedure should have set the data for us. | 185 // The window procedure should have set the data for us. |
| 185 DCHECK(win_util::GetWindowUserData(hwnd_) == this); | 186 DCHECK(win_util::GetWindowUserData(hwnd_) == this); |
| 186 | 187 |
| 187 root_view_->OnWidgetCreated(); | 188 root_view_->OnWidgetCreated(); |
| 188 | 189 |
| 189 if ((window_style_ & WS_CHILD) == 0) { | 190 if (has_own_focus_manager) { |
| 190 // Top-level widgets get a FocusManager. | 191 FocusManager::CreateFocusManager(hwnd_, GetRootView()); |
| 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 | |
| 434 void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { | 422 void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { |
| 435 if (use_layered_buffer_ == use_layered_buffer) | 423 if (use_layered_buffer_ == use_layered_buffer) |
| 436 return; | 424 return; |
| 437 | 425 |
| 438 use_layered_buffer_ = use_layered_buffer; | 426 use_layered_buffer_ = use_layered_buffer; |
| 439 if (!hwnd_) | 427 if (!hwnd_) |
| 440 return; | 428 return; |
| 441 | 429 |
| 442 if (use_layered_buffer_) { | 430 if (use_layered_buffer_) { |
| 443 // Force creation of the buffer at the right size. | 431 // Force creation of the buffer at the right size. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 465 reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); | 453 reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); |
| 466 if (root_view) | 454 if (root_view) |
| 467 return root_view; | 455 return root_view; |
| 468 | 456 |
| 469 // Enumerate all children and check if they have a RootView. | 457 // Enumerate all children and check if they have a RootView. |
| 470 EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast<LPARAM>(&root_view)); | 458 EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast<LPARAM>(&root_view)); |
| 471 | 459 |
| 472 return root_view; | 460 return root_view; |
| 473 } | 461 } |
| 474 | 462 |
| 475 // static | 463 /////////////////////////////////////////////////////////////////////////////// |
| 476 WidgetWin* WidgetWin::GetWidget(HWND hwnd) { | |
| 477 return reinterpret_cast<WidgetWin*>(win_util::GetWindowUserData(hwnd)); | |
| 478 } | |
| 479 | |
| 480 //////////////////////////////////////////////////////////////////////////////// | |
| 481 // MessageLoop::Observer | 464 // MessageLoop::Observer |
| 482 | 465 |
| 483 void WidgetWin::WillProcessMessage(const MSG& msg) { | 466 void WidgetWin::WillProcessMessage(const MSG& msg) { |
| 484 } | 467 } |
| 485 | 468 |
| 486 void WidgetWin::DidProcessMessage(const MSG& msg) { | 469 void WidgetWin::DidProcessMessage(const MSG& msg) { |
| 487 if (root_view_->NeedsPainting(true)) { | 470 if (root_view_->NeedsPainting(true)) { |
| 488 PaintNow(root_view_->GetScheduledPaintRect()); | 471 PaintNow(root_view_->GetScheduledPaintRect()); |
| 489 } | 472 } |
| 490 } | 473 } |
| 491 | 474 |
| 492 //////////////////////////////////////////////////////////////////////////////// | 475 /////////////////////////////////////////////////////////////////////////////// |
| 493 // FocusTraversable | 476 // FocusTraversable |
| 494 | 477 |
| 495 View* WidgetWin::FindNextFocusableView( | 478 View* WidgetWin::FindNextFocusableView( |
| 496 View* starting_view, bool reverse, Direction direction, | 479 View* starting_view, bool reverse, Direction direction, |
| 497 bool check_starting_view, FocusTraversable** focus_traversable, | 480 bool check_starting_view, FocusTraversable** focus_traversable, |
| 498 View** focus_traversable_view) { | 481 View** focus_traversable_view) { |
| 499 return root_view_->FindNextFocusableView(starting_view, | 482 return root_view_->FindNextFocusableView(starting_view, |
| 500 reverse, | 483 reverse, |
| 501 direction, | 484 direction, |
| 502 check_starting_view, | 485 check_starting_view, |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 | 1032 |
| 1050 // First allow messages sent by child controls to be processed directly by | 1033 // First allow messages sent by child controls to be processed directly by |
| 1051 // their associated views. If such a view is present, it will handle the | 1034 // their associated views. If such a view is present, it will handle the |
| 1052 // message *instead of* this WidgetWin. | 1035 // message *instead of* this WidgetWin. |
| 1053 if (ProcessNativeControlMessage(message, w_param, l_param, &result)) | 1036 if (ProcessNativeControlMessage(message, w_param, l_param, &result)) |
| 1054 return result; | 1037 return result; |
| 1055 | 1038 |
| 1056 // Otherwise we handle everything else. | 1039 // Otherwise we handle everything else. |
| 1057 if (!widget->ProcessWindowMessage(window, message, w_param, l_param, result)) | 1040 if (!widget->ProcessWindowMessage(window, message, w_param, l_param, result)) |
| 1058 result = DefWindowProc(window, message, w_param, l_param); | 1041 result = DefWindowProc(window, message, w_param, l_param); |
| 1059 if (message == WM_NCDESTROY) | 1042 if (message == WM_NCDESTROY) { |
| 1043 widget->hwnd_ = NULL; |
| 1060 widget->OnFinalMessage(window); | 1044 widget->OnFinalMessage(window); |
| 1045 } |
| 1061 if (message == WM_ACTIVATE) | 1046 if (message == WM_ACTIVATE) |
| 1062 PostProcessActivateMessage(widget, LOWORD(w_param)); | 1047 PostProcessActivateMessage(widget, LOWORD(w_param)); |
| 1063 return result; | 1048 return result; |
| 1064 } | 1049 } |
| 1065 | 1050 |
| 1066 // static | 1051 // static |
| 1067 void WidgetWin::PostProcessActivateMessage(WidgetWin* widget, | 1052 void WidgetWin::PostProcessActivateMessage(WidgetWin* widget, |
| 1068 int activation_state) { | 1053 int activation_state) { |
| 1069 if (!widget->focus_manager_.get()) { | 1054 FocusManager* focus_manager = |
| 1055 FocusManager::GetFocusManager(widget->GetNativeView()); |
| 1056 if (!focus_manager) { |
| 1070 NOTREACHED(); | 1057 NOTREACHED(); |
| 1071 return; | 1058 return; |
| 1072 } | 1059 } |
| 1073 if (WA_INACTIVE == activation_state) { | 1060 if (WA_INACTIVE == activation_state) { |
| 1074 widget->focus_manager_->StoreFocusedView(); | 1061 focus_manager->StoreFocusedView(); |
| 1075 } else { | 1062 } else { |
| 1076 // We must restore the focus after the message has been DefProc'ed as it | 1063 // We must restore the focus after the message has been DefProc'ed as it |
| 1077 // does set the focus to the last focused HWND. | 1064 // does set the focus to the last focused HWND. |
| 1078 widget->focus_manager_->RestoreFocusedView(); | 1065 focus_manager->RestoreFocusedView(); |
| 1079 } | 1066 } |
| 1080 } | 1067 } |
| 1081 } // namespace views | 1068 } // namespace views |
| OLD | NEW |