| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 void WidgetWin::SetShape(const gfx::Path& shape) { | 259 void WidgetWin::SetShape(const gfx::Path& shape) { |
| 260 SetWindowRgn(shape.CreateHRGN(), TRUE); | 260 SetWindowRgn(shape.CreateHRGN(), TRUE); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void WidgetWin::Close() { | 263 void WidgetWin::Close() { |
| 264 if (!IsWindow()) | 264 if (!IsWindow()) |
| 265 return; // No need to do anything. | 265 return; // No need to do anything. |
| 266 | 266 |
| 267 // Let's hide ourselves right away. | 267 // Let's hide ourselves right away. |
| 268 Hide(); | 268 Hide(); |
| 269 |
| 269 if (close_widget_factory_.empty()) { | 270 if (close_widget_factory_.empty()) { |
| 270 // And we delay the close so that if we are called from an ATL callback, | 271 // And we delay the close so that if we are called from an ATL callback, |
| 271 // we don't destroy the window before the callback returned (as the caller | 272 // we don't destroy the window before the callback returned (as the caller |
| 272 // may delete ourselves on destroy and the ATL callback would still | 273 // may delete ourselves on destroy and the ATL callback would still |
| 273 // dereference us when the callback returns). | 274 // dereference us when the callback returns). |
| 274 MessageLoop::current()->PostTask(FROM_HERE, | 275 MessageLoop::current()->PostTask(FROM_HERE, |
| 275 close_widget_factory_.NewRunnableMethod( | 276 close_widget_factory_.NewRunnableMethod( |
| 276 &WidgetWin::CloseNow)); | 277 &WidgetWin::CloseNow)); |
| 277 } | 278 } |
| 278 } | 279 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } | 413 } |
| 413 | 414 |
| 414 Window* WidgetWin::GetWindow() { | 415 Window* WidgetWin::GetWindow() { |
| 415 return GetWindowImpl(hwnd_); | 416 return GetWindowImpl(hwnd_); |
| 416 } | 417 } |
| 417 | 418 |
| 418 const Window* WidgetWin::GetWindow() const { | 419 const Window* WidgetWin::GetWindow() const { |
| 419 return GetWindowImpl(hwnd_); | 420 return GetWindowImpl(hwnd_); |
| 420 } | 421 } |
| 421 | 422 |
| 423 FocusManager* WidgetWin::GetFocusManager() { |
| 424 if (focus_manager_.get()) |
| 425 return focus_manager_.get(); |
| 426 |
| 427 WidgetWin* widget = static_cast<WidgetWin*>(GetRootWidget()); |
| 428 if (widget && widget != this) { |
| 429 // WidgetWin subclasses may override GetFocusManager(), for example for |
| 430 // dealing with cases where the widget has been unparented. |
| 431 return widget->GetFocusManager(); |
| 432 } |
| 433 return NULL; |
| 434 } |
| 435 |
| 422 void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { | 436 void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { |
| 423 if (use_layered_buffer_ == use_layered_buffer) | 437 if (use_layered_buffer_ == use_layered_buffer) |
| 424 return; | 438 return; |
| 425 | 439 |
| 426 use_layered_buffer_ = use_layered_buffer; | 440 use_layered_buffer_ = use_layered_buffer; |
| 427 if (!hwnd_) | 441 if (!hwnd_) |
| 428 return; | 442 return; |
| 429 | 443 |
| 430 if (use_layered_buffer_) { | 444 if (use_layered_buffer_) { |
| 431 // Force creation of the buffer at the right size. | 445 // Force creation of the buffer at the right size. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 453 reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); | 467 reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); |
| 454 if (root_view) | 468 if (root_view) |
| 455 return root_view; | 469 return root_view; |
| 456 | 470 |
| 457 // Enumerate all children and check if they have a RootView. | 471 // Enumerate all children and check if they have a RootView. |
| 458 EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast<LPARAM>(&root_view)); | 472 EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast<LPARAM>(&root_view)); |
| 459 | 473 |
| 460 return root_view; | 474 return root_view; |
| 461 } | 475 } |
| 462 | 476 |
| 463 /////////////////////////////////////////////////////////////////////////////// | 477 // static |
| 478 WidgetWin* WidgetWin::GetWidget(HWND hwnd) { |
| 479 return reinterpret_cast<WidgetWin*>(win_util::GetWindowUserData(hwnd)); |
| 480 } |
| 481 |
| 482 //////////////////////////////////////////////////////////////////////////////// |
| 464 // MessageLoop::Observer | 483 // MessageLoop::Observer |
| 465 | 484 |
| 466 void WidgetWin::WillProcessMessage(const MSG& msg) { | 485 void WidgetWin::WillProcessMessage(const MSG& msg) { |
| 467 } | 486 } |
| 468 | 487 |
| 469 void WidgetWin::DidProcessMessage(const MSG& msg) { | 488 void WidgetWin::DidProcessMessage(const MSG& msg) { |
| 470 if (root_view_->NeedsPainting(true)) { | 489 if (root_view_->NeedsPainting(true)) { |
| 471 PaintNow(root_view_->GetScheduledPaintRect()); | 490 PaintNow(root_view_->GetScheduledPaintRect()); |
| 472 } | 491 } |
| 473 } | 492 } |
| 474 | 493 |
| 475 /////////////////////////////////////////////////////////////////////////////// | 494 //////////////////////////////////////////////////////////////////////////////// |
| 476 // FocusTraversable | 495 // FocusTraversable |
| 477 | 496 |
| 478 View* WidgetWin::FindNextFocusableView( | 497 View* WidgetWin::FindNextFocusableView( |
| 479 View* starting_view, bool reverse, Direction direction, | 498 View* starting_view, bool reverse, Direction direction, |
| 480 bool check_starting_view, FocusTraversable** focus_traversable, | 499 bool check_starting_view, FocusTraversable** focus_traversable, |
| 481 View** focus_traversable_view) { | 500 View** focus_traversable_view) { |
| 482 return root_view_->FindNextFocusableView(starting_view, | 501 return root_view_->FindNextFocusableView(starting_view, |
| 483 reverse, | 502 reverse, |
| 484 direction, | 503 direction, |
| 485 check_starting_view, | 504 check_starting_view, |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 | 1051 |
| 1033 // First allow messages sent by child controls to be processed directly by | 1052 // 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 | 1053 // their associated views. If such a view is present, it will handle the |
| 1035 // message *instead of* this WidgetWin. | 1054 // message *instead of* this WidgetWin. |
| 1036 if (ProcessNativeControlMessage(message, w_param, l_param, &result)) | 1055 if (ProcessNativeControlMessage(message, w_param, l_param, &result)) |
| 1037 return result; | 1056 return result; |
| 1038 | 1057 |
| 1039 // Otherwise we handle everything else. | 1058 // Otherwise we handle everything else. |
| 1040 if (!widget->ProcessWindowMessage(window, message, w_param, l_param, result)) | 1059 if (!widget->ProcessWindowMessage(window, message, w_param, l_param, result)) |
| 1041 result = DefWindowProc(window, message, w_param, l_param); | 1060 result = DefWindowProc(window, message, w_param, l_param); |
| 1042 if (message == WM_NCDESTROY) { | 1061 if (message == WM_NCDESTROY) |
| 1043 widget->hwnd_ = NULL; | |
| 1044 widget->OnFinalMessage(window); | 1062 widget->OnFinalMessage(window); |
| 1045 } | |
| 1046 if (message == WM_ACTIVATE) | 1063 if (message == WM_ACTIVATE) |
| 1047 PostProcessActivateMessage(widget, LOWORD(w_param)); | 1064 PostProcessActivateMessage(widget, LOWORD(w_param)); |
| 1048 return result; | 1065 return result; |
| 1049 } | 1066 } |
| 1050 | 1067 |
| 1051 // static | 1068 // static |
| 1052 void WidgetWin::PostProcessActivateMessage(WidgetWin* widget, | 1069 void WidgetWin::PostProcessActivateMessage(WidgetWin* widget, |
| 1053 int activation_state) { | 1070 int activation_state) { |
| 1054 FocusManager* focus_manager = | 1071 if (!widget->focus_manager_.get()) { |
| 1055 FocusManager::GetFocusManager(widget->GetNativeView()); | |
| 1056 if (!focus_manager) { | |
| 1057 NOTREACHED(); | 1072 NOTREACHED(); |
| 1058 return; | 1073 return; |
| 1059 } | 1074 } |
| 1060 if (WA_INACTIVE == activation_state) { | 1075 if (WA_INACTIVE == activation_state) { |
| 1061 focus_manager->StoreFocusedView(); | 1076 widget->focus_manager_->StoreFocusedView(); |
| 1062 } else { | 1077 } else { |
| 1063 // We must restore the focus after the message has been DefProc'ed as it | 1078 // We must restore the focus after the message has been DefProc'ed as it |
| 1064 // does set the focus to the last focused HWND. | 1079 // does set the focus to the last focused HWND. |
| 1065 focus_manager->RestoreFocusedView(); | 1080 widget->focus_manager_->RestoreFocusedView(); |
| 1066 } | 1081 } |
| 1067 } | 1082 } |
| 1068 } // namespace views | 1083 } // namespace views |
| OLD | NEW |