Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: ui/views/widget/native_widget_win.cc

Issue 10870110: Move more code from NWW to HWNDMessageHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/widget/native_widget_win.h ('k') | ui/views/win/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/widget/native_widget_win.h" 5 #include "ui/views/widget/native_widget_win.h"
6 6
7 #include <dwmapi.h> 7 #include <dwmapi.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 11 matching lines...) Expand all
22 #include "ui/base/keycodes/keyboard_code_conversion_win.h" 22 #include "ui/base/keycodes/keyboard_code_conversion_win.h"
23 #include "ui/base/l10n/l10n_util_win.h" 23 #include "ui/base/l10n/l10n_util_win.h"
24 #include "ui/base/theme_provider.h" 24 #include "ui/base/theme_provider.h"
25 #include "ui/base/view_prop.h" 25 #include "ui/base/view_prop.h"
26 #include "ui/base/win/hwnd_util.h" 26 #include "ui/base/win/hwnd_util.h"
27 #include "ui/base/win/mouse_wheel_util.h" 27 #include "ui/base/win/mouse_wheel_util.h"
28 #include "ui/base/win/shell.h" 28 #include "ui/base/win/shell.h"
29 #include "ui/gfx/canvas.h" 29 #include "ui/gfx/canvas.h"
30 #include "ui/gfx/canvas_paint.h" 30 #include "ui/gfx/canvas_paint.h"
31 #include "ui/gfx/canvas_skia_paint.h" 31 #include "ui/gfx/canvas_skia_paint.h"
32 #include "ui/gfx/icon_util.h"
33 #include "ui/gfx/path.h" 32 #include "ui/gfx/path.h"
34 #include "ui/gfx/screen.h" 33 #include "ui/gfx/screen.h"
35 #include "ui/views/accessibility/native_view_accessibility_win.h" 34 #include "ui/views/accessibility/native_view_accessibility_win.h"
36 #include "ui/views/controls/native_control_win.h" 35 #include "ui/views/controls/native_control_win.h"
37 #include "ui/views/controls/textfield/native_textfield_views.h" 36 #include "ui/views/controls/textfield/native_textfield_views.h"
38 #include "ui/views/drag_utils.h" 37 #include "ui/views/drag_utils.h"
39 #include "ui/views/focus/accelerator_handler.h" 38 #include "ui/views/focus/accelerator_handler.h"
40 #include "ui/views/focus/view_storage.h" 39 #include "ui/views/focus/view_storage.h"
41 #include "ui/views/focus/widget_focus_manager.h" 40 #include "ui/views/focus/widget_focus_manager.h"
42 #include "ui/views/ime/input_method_win.h" 41 #include "ui/views/ime/input_method_win.h"
43 #include "ui/views/views_delegate.h"
44 #include "ui/views/widget/aero_tooltip_manager.h" 42 #include "ui/views/widget/aero_tooltip_manager.h"
45 #include "ui/views/widget/child_window_message_processor.h"
46 #include "ui/views/widget/drop_target_win.h" 43 #include "ui/views/widget/drop_target_win.h"
47 #include "ui/views/widget/monitor_win.h" 44 #include "ui/views/widget/monitor_win.h"
48 #include "ui/views/widget/native_widget_delegate.h" 45 #include "ui/views/widget/native_widget_delegate.h"
49 #include "ui/views/widget/root_view.h" 46 #include "ui/views/widget/root_view.h"
50 #include "ui/views/widget/widget_delegate.h" 47 #include "ui/views/widget/widget_delegate.h"
51 #include "ui/views/widget/widget_hwnd_utils.h" 48 #include "ui/views/widget/widget_hwnd_utils.h"
52 #include "ui/views/win/fullscreen_handler.h" 49 #include "ui/views/win/fullscreen_handler.h"
53 #include "ui/views/win/hwnd_message_handler.h" 50 #include "ui/views/win/hwnd_message_handler.h"
54 #include "ui/views/window/native_frame_view.h" 51 #include "ui/views/window/native_frame_view.h"
55 52
56 #if !defined(USE_AURA) 53 #if !defined(USE_AURA)
57 #include "base/command_line.h" 54 #include "base/command_line.h"
58 #include "ui/base/ui_base_switches.h" 55 #include "ui/base/ui_base_switches.h"
59 #endif 56 #endif
60 57
61 #pragma comment(lib, "dwmapi.lib") 58 #pragma comment(lib, "dwmapi.lib")
62 59
63 using ui::ViewProp; 60 using ui::ViewProp;
64 61
65 namespace views { 62 namespace views {
66 63
67 namespace { 64 namespace {
68 65
69 // Get the source HWND of the specified message. Depending on the message, the
70 // source HWND is encoded in either the WPARAM or the LPARAM value.
71 HWND GetControlHWNDForMessage(UINT message, WPARAM w_param, LPARAM l_param) {
72 // Each of the following messages can be sent by a child HWND and must be
73 // forwarded to its associated NativeControlWin for handling.
74 switch (message) {
75 case WM_NOTIFY:
76 return reinterpret_cast<NMHDR*>(l_param)->hwndFrom;
77 case WM_COMMAND:
78 return reinterpret_cast<HWND>(l_param);
79 case WM_CONTEXTMENU:
80 return reinterpret_cast<HWND>(w_param);
81 case WM_CTLCOLORBTN:
82 case WM_CTLCOLORSTATIC:
83 return reinterpret_cast<HWND>(l_param);
84 }
85 return NULL;
86 }
87
88 // Some messages may be sent to us by a child HWND. If this is the case, this
89 // function will forward those messages on to the object associated with the
90 // source HWND and return true, in which case the window procedure must not do
91 // any further processing of the message. If there is no associated
92 // ChildWindowMessageProcessor, the return value will be false and the WndProc
93 // can continue processing the message normally. |l_result| contains the result
94 // of the message processing by the control and must be returned by the WndProc
95 // if the return value is true.
96 bool ProcessChildWindowMessage(UINT message,
97 WPARAM w_param,
98 LPARAM l_param,
99 LRESULT* l_result) {
100 *l_result = 0;
101
102 HWND control_hwnd = GetControlHWNDForMessage(message, w_param, l_param);
103 if (IsWindow(control_hwnd)) {
104 ChildWindowMessageProcessor* processor =
105 ChildWindowMessageProcessor::Get(control_hwnd);
106 if (processor)
107 return processor->ProcessMessage(message, w_param, l_param, l_result);
108 }
109
110 return false;
111 }
112
113 // Enumeration callback for NativeWidget::GetAllChildWidgets(). Called for each 66 // Enumeration callback for NativeWidget::GetAllChildWidgets(). Called for each
114 // child HWND beneath the original HWND. 67 // child HWND beneath the original HWND.
115 BOOL CALLBACK EnumerateChildWindowsForNativeWidgets(HWND hwnd, LPARAM l_param) { 68 BOOL CALLBACK EnumerateChildWindowsForNativeWidgets(HWND hwnd, LPARAM l_param) {
116 Widget* widget = Widget::GetWidgetForNativeView(hwnd); 69 Widget* widget = Widget::GetWidgetForNativeView(hwnd);
117 if (widget) { 70 if (widget) {
118 Widget::Widgets* widgets = reinterpret_cast<Widget::Widgets*>(l_param); 71 Widget::Widgets* widgets = reinterpret_cast<Widget::Widgets*>(l_param);
119 widgets->insert(widget); 72 widgets->insert(widget);
120 } 73 }
121 return TRUE; 74 return TRUE;
122 } 75 }
123 76
124 // Enables or disables the menu item for the specified command and menu.
125 void EnableMenuItem(HMENU menu, UINT command, bool enabled) {
126 UINT flags = MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_DISABLED | MF_GRAYED);
127 EnableMenuItem(menu, command, flags);
128 }
129
130 // Links the HWND to its NativeWidget. 77 // Links the HWND to its NativeWidget.
131 const char* const kNativeWidgetKey = "__VIEWS_NATIVE_WIDGET__"; 78 const char* const kNativeWidgetKey = "__VIEWS_NATIVE_WIDGET__";
132 79
133 const int kDragFrameWindowAlpha = 200; 80 const int kDragFrameWindowAlpha = 200;
134 81
135 } // namespace 82 } // namespace
136 83
137 // static 84 // static
138 bool NativeWidgetWin::screen_reader_active_ = false; 85 bool NativeWidgetWin::screen_reader_active_ = false;
139 86
140 //////////////////////////////////////////////////////////////////////////////// 87 ////////////////////////////////////////////////////////////////////////////////
141 // NativeWidgetWin, public: 88 // NativeWidgetWin, public:
142 89
143 NativeWidgetWin::NativeWidgetWin(internal::NativeWidgetDelegate* delegate) 90 NativeWidgetWin::NativeWidgetWin(internal::NativeWidgetDelegate* delegate)
144 : delegate_(delegate), 91 : delegate_(delegate),
145 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
146 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 92 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
147 restore_focus_when_enabled_(false),
148 accessibility_view_events_index_(-1), 93 accessibility_view_events_index_(-1),
149 accessibility_view_events_(kMaxAccessibilityViewEvents), 94 accessibility_view_events_(kMaxAccessibilityViewEvents),
150 restored_enabled_(false),
151 has_non_client_view_(false), 95 has_non_client_view_(false),
152 ALLOW_THIS_IN_INITIALIZER_LIST( 96 ALLOW_THIS_IN_INITIALIZER_LIST(
153 message_handler_(new HWNDMessageHandler(this))) { 97 message_handler_(new HWNDMessageHandler(this))) {
154 } 98 }
155 99
156 NativeWidgetWin::~NativeWidgetWin() { 100 NativeWidgetWin::~NativeWidgetWin() {
157 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 101 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
158 delete delegate_; 102 delete delegate_;
159 else 103 else
160 CloseNow(); 104 CloseNow();
161 } 105 }
162 106
163 // static 107 // static
164 gfx::Font NativeWidgetWin::GetWindowTitleFont() { 108 gfx::Font NativeWidgetWin::GetWindowTitleFont() {
165 NONCLIENTMETRICS ncm; 109 NONCLIENTMETRICS ncm;
166 base::win::GetNonClientMetrics(&ncm); 110 base::win::GetNonClientMetrics(&ncm);
167 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); 111 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont));
168 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); 112 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont)));
169 return gfx::Font(caption_font); 113 return gfx::Font(caption_font);
170 } 114 }
171 115
172 void NativeWidgetWin::Show(int show_state) { 116 void NativeWidgetWin::Show(int show_state) {
173 ShowWindow(show_state); 117 message_handler_->Show(show_state);
174 // When launched from certain programs like bash and Windows Live Messenger,
175 // show_state is set to SW_HIDE, so we need to correct that condition. We
176 // don't just change show_state to SW_SHOWNORMAL because MSDN says we must
177 // always first call ShowWindow with the specified value from STARTUPINFO,
178 // otherwise all future ShowWindow calls will be ignored (!!#@@#!). Instead,
179 // we call ShowWindow again in this case.
180 if (show_state == SW_HIDE) {
181 show_state = SW_SHOWNORMAL;
182 ShowWindow(show_state);
183 }
184
185 // We need to explicitly activate the window if we've been shown with a state
186 // that should activate, because if we're opened from a desktop shortcut while
187 // an existing window is already running it doesn't seem to be enough to use
188 // one of these flags to activate the window.
189 if (show_state == SW_SHOWNORMAL || show_state == SW_SHOWMAXIMIZED)
190 Activate();
191
192 SetInitialFocus();
193 } 118 }
194 119
195 View* NativeWidgetWin::GetAccessibilityViewEventAt(int id) { 120 View* NativeWidgetWin::GetAccessibilityViewEventAt(int id) {
196 // Convert from MSAA child id. 121 // Convert from MSAA child id.
197 id = -(id + 1); 122 id = -(id + 1);
198 DCHECK(id >= 0 && id < kMaxAccessibilityViewEvents); 123 DCHECK(id >= 0 && id < kMaxAccessibilityViewEvents);
199 return accessibility_view_events_[id]; 124 return accessibility_view_events_[id];
200 } 125 }
201 126
202 int NativeWidgetWin::AddAccessibilityViewEvent(View* view) { 127 int NativeWidgetWin::AddAccessibilityViewEvent(View* view) {
203 accessibility_view_events_index_ = 128 accessibility_view_events_index_ =
204 (accessibility_view_events_index_ + 1) % kMaxAccessibilityViewEvents; 129 (accessibility_view_events_index_ + 1) % kMaxAccessibilityViewEvents;
205 accessibility_view_events_[accessibility_view_events_index_] = view; 130 accessibility_view_events_[accessibility_view_events_index_] = view;
206 131
207 // Convert to MSAA child id. 132 // Convert to MSAA child id.
208 return -(accessibility_view_events_index_ + 1); 133 return -(accessibility_view_events_index_ + 1);
209 } 134 }
210 135
211 void NativeWidgetWin::ClearAccessibilityViewEvent(View* view) { 136 void NativeWidgetWin::ClearAccessibilityViewEvent(View* view) {
212 for (std::vector<View*>::iterator it = accessibility_view_events_.begin(); 137 for (std::vector<View*>::iterator it = accessibility_view_events_.begin();
213 it != accessibility_view_events_.end(); 138 it != accessibility_view_events_.end();
214 ++it) { 139 ++it) {
215 if (*it == view) 140 if (*it == view)
216 *it = NULL; 141 *it = NULL;
217 } 142 }
218 } 143 }
219 144
220 //////////////////////////////////////////////////////////////////////////////// 145 ////////////////////////////////////////////////////////////////////////////////
221 // NativeWidgetWin, CompositorDelegate implementation:
222
223 ////////////////////////////////////////////////////////////////////////////////
224 // NativeWidgetWin, NativeWidget implementation: 146 // NativeWidgetWin, NativeWidget implementation:
225 147
226 void NativeWidgetWin::InitNativeWidget(const Widget::InitParams& params) { 148 void NativeWidgetWin::InitNativeWidget(const Widget::InitParams& params) {
227 SetInitParams(params); 149 SetInitParams(params);
228 150
229 message_handler_->Init(params.bounds); 151 message_handler_->Init(params.bounds);
230 152
231 // Create the window. 153 // Create the window.
232 WindowImpl::Init(params.GetParent(), params.bounds); 154 WindowImpl::Init(params.GetParent(), params.bounds);
233 } 155 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 return tooltip_manager_.get(); 234 return tooltip_manager_.get();
313 } 235 }
314 236
315 bool NativeWidgetWin::IsScreenReaderActive() const { 237 bool NativeWidgetWin::IsScreenReaderActive() const {
316 return screen_reader_active_; 238 return screen_reader_active_;
317 } 239 }
318 240
319 void NativeWidgetWin::SendNativeAccessibilityEvent( 241 void NativeWidgetWin::SendNativeAccessibilityEvent(
320 View* view, 242 View* view,
321 ui::AccessibilityTypes::Event event_type) { 243 ui::AccessibilityTypes::Event event_type) {
322 int child_id = AddAccessibilityViewEvent(view); 244 message_handler_->SendNativeAccessibilityEvent(
323 message_handler_->SendNativeAccessibilityEvent(child_id, event_type); 245 AddAccessibilityViewEvent(view), event_type);
324 } 246 }
325 247
326 void NativeWidgetWin::SetCapture() { 248 void NativeWidgetWin::SetCapture() {
327 message_handler_->SetCapture(); 249 message_handler_->SetCapture();
328 } 250 }
329 251
330 void NativeWidgetWin::ReleaseCapture() { 252 void NativeWidgetWin::ReleaseCapture() {
331 message_handler_->ReleaseCapture(); 253 message_handler_->ReleaseCapture();
332 } 254 }
333 255
(...skipping 13 matching lines...) Expand all
347 message_handler_->CenterWindow(size); 269 message_handler_->CenterWindow(size);
348 } 270 }
349 271
350 void NativeWidgetWin::GetWindowPlacement( 272 void NativeWidgetWin::GetWindowPlacement(
351 gfx::Rect* bounds, 273 gfx::Rect* bounds,
352 ui::WindowShowState* show_state) const { 274 ui::WindowShowState* show_state) const {
353 message_handler_->GetWindowPlacement(bounds, show_state); 275 message_handler_->GetWindowPlacement(bounds, show_state);
354 } 276 }
355 277
356 void NativeWidgetWin::SetWindowTitle(const string16& title) { 278 void NativeWidgetWin::SetWindowTitle(const string16& title) {
357 SetWindowText(GetNativeView(), title.c_str()); 279 message_handler_->SetTitle(title);
358 SetAccessibleName(title);
359 } 280 }
360 281
361 void NativeWidgetWin::SetWindowIcons(const gfx::ImageSkia& window_icon, 282 void NativeWidgetWin::SetWindowIcons(const gfx::ImageSkia& window_icon,
362 const gfx::ImageSkia& app_icon) { 283 const gfx::ImageSkia& app_icon) {
363 if (!window_icon.isNull()) { 284 message_handler_->SetWindowIcons(window_icon, app_icon);
364 HICON windows_icon = IconUtil::CreateHICONFromSkBitmap(window_icon);
365 // We need to make sure to destroy the previous icon, otherwise we'll leak
366 // these GDI objects until we crash!
367 HICON old_icon = reinterpret_cast<HICON>(
368 SendMessage(GetNativeView(), WM_SETICON, ICON_SMALL,
369 reinterpret_cast<LPARAM>(windows_icon)));
370 if (old_icon)
371 DestroyIcon(old_icon);
372 }
373 if (!app_icon.isNull()) {
374 HICON windows_icon = IconUtil::CreateHICONFromSkBitmap(app_icon);
375 HICON old_icon = reinterpret_cast<HICON>(
376 SendMessage(GetNativeView(), WM_SETICON, ICON_BIG,
377 reinterpret_cast<LPARAM>(windows_icon)));
378 if (old_icon)
379 DestroyIcon(old_icon);
380 }
381 } 285 }
382 286
383 void NativeWidgetWin::SetAccessibleName(const string16& name) { 287 void NativeWidgetWin::SetAccessibleName(const string16& name) {
384 base::win::ScopedComPtr<IAccPropServices> pAccPropServices; 288 message_handler_->SetAccessibleName(name);
385 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER,
386 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices));
387 if (SUCCEEDED(hr))
388 hr = pAccPropServices->SetHwndPropStr(GetNativeView(), OBJID_CLIENT,
389 CHILDID_SELF, PROPID_ACC_NAME,
390 name.c_str());
391 } 289 }
392 290
393 void NativeWidgetWin::SetAccessibleRole(ui::AccessibilityTypes::Role role) { 291 void NativeWidgetWin::SetAccessibleRole(ui::AccessibilityTypes::Role role) {
394 base::win::ScopedComPtr<IAccPropServices> pAccPropServices; 292 message_handler_->SetAccessibleRole(role);
395 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER,
396 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices));
397 if (SUCCEEDED(hr)) {
398 VARIANT var;
399 if (role) {
400 var.vt = VT_I4;
401 var.lVal = NativeViewAccessibilityWin::MSAARole(role);
402 hr = pAccPropServices->SetHwndProp(GetNativeView(), OBJID_CLIENT,
403 CHILDID_SELF, PROPID_ACC_ROLE, var);
404 }
405 }
406 } 293 }
407 294
408 void NativeWidgetWin::SetAccessibleState(ui::AccessibilityTypes::State state) { 295 void NativeWidgetWin::SetAccessibleState(ui::AccessibilityTypes::State state) {
409 base::win::ScopedComPtr<IAccPropServices> pAccPropServices; 296 message_handler_->SetAccessibleState(state);
410 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER,
411 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices));
412 if (SUCCEEDED(hr)) {
413 VARIANT var;
414 if (state) {
415 var.vt = VT_I4;
416 var.lVal = NativeViewAccessibilityWin::MSAAState(state);
417 hr = pAccPropServices->SetHwndProp(GetNativeView(), OBJID_CLIENT,
418 CHILDID_SELF, PROPID_ACC_STATE, var);
419 }
420 }
421 } 297 }
422 298
423 void NativeWidgetWin::InitModalType(ui::ModalType modal_type) { 299 void NativeWidgetWin::InitModalType(ui::ModalType modal_type) {
424 message_handler_->InitModalType(modal_type); 300 message_handler_->InitModalType(modal_type);
425 } 301 }
426 302
427 gfx::Rect NativeWidgetWin::GetWindowBoundsInScreen() const { 303 gfx::Rect NativeWidgetWin::GetWindowBoundsInScreen() const {
428 return message_handler_->GetWindowBoundsInScreen(); 304 return message_handler_->GetWindowBoundsInScreen();
429 } 305 }
430 306
(...skipping 23 matching lines...) Expand all
454 330
455 void NativeWidgetWin::StackBelow(gfx::NativeView native_view) { 331 void NativeWidgetWin::StackBelow(gfx::NativeView native_view) {
456 NOTIMPLEMENTED(); 332 NOTIMPLEMENTED();
457 } 333 }
458 334
459 void NativeWidgetWin::SetShape(gfx::NativeRegion region) { 335 void NativeWidgetWin::SetShape(gfx::NativeRegion region) {
460 message_handler_->SetRegion(region); 336 message_handler_->SetRegion(region);
461 } 337 }
462 338
463 void NativeWidgetWin::Close() { 339 void NativeWidgetWin::Close() {
464 if (!IsWindow()) 340 message_handler_->Close();
465 return; // No need to do anything.
466
467 // Let's hide ourselves right away.
468 Hide();
469
470 // Modal dialog windows disable their owner windows; re-enable them now so
471 // they can activate as foreground windows upon this window's destruction.
472 RestoreEnabledIfNecessary();
473
474 if (!close_widget_factory_.HasWeakPtrs()) {
475 // And we delay the close so that if we are called from an ATL callback,
476 // we don't destroy the window before the callback returned (as the caller
477 // may delete ourselves on destroy and the ATL callback would still
478 // dereference us when the callback returns).
479 MessageLoop::current()->PostTask(
480 FROM_HERE,
481 base::Bind(&NativeWidgetWin::CloseNow,
482 close_widget_factory_.GetWeakPtr()));
483 }
484 } 341 }
485 342
486 void NativeWidgetWin::CloseNow() { 343 void NativeWidgetWin::CloseNow() {
487 message_handler_->CloseNow(); 344 message_handler_->CloseNow();
488 } 345 }
489 346
490 void NativeWidgetWin::Show() { 347 void NativeWidgetWin::Show() {
491 if (!IsWindow()) 348 message_handler_->Show();
492 return;
493
494 ShowWindow(SW_SHOWNOACTIVATE);
495 SetInitialFocus();
496 } 349 }
497 350
498 void NativeWidgetWin::Hide() { 351 void NativeWidgetWin::Hide() {
499 message_handler_->Hide(); 352 message_handler_->Hide();
500 } 353 }
501 354
502 void NativeWidgetWin::ShowMaximizedWithBounds( 355 void NativeWidgetWin::ShowMaximizedWithBounds(
503 const gfx::Rect& restored_bounds) { 356 const gfx::Rect& restored_bounds) {
504 message_handler_->ShowMaximizedWithBounds(restored_bounds); 357 message_handler_->ShowMaximizedWithBounds(restored_bounds);
505 } 358 }
506 359
507 void NativeWidgetWin::ShowWithWindowState(ui::WindowShowState show_state) { 360 void NativeWidgetWin::ShowWithWindowState(ui::WindowShowState show_state) {
508 DWORD native_show_state; 361 message_handler_->ShowWindowWithState(show_state);
509 switch (show_state) {
510 case ui::SHOW_STATE_INACTIVE:
511 native_show_state = SW_SHOWNOACTIVATE;
512 break;
513 case ui::SHOW_STATE_MAXIMIZED:
514 native_show_state = SW_SHOWMAXIMIZED;
515 break;
516 case ui::SHOW_STATE_MINIMIZED:
517 native_show_state = SW_SHOWMINIMIZED;
518 break;
519 default:
520 native_show_state = GetShowState();
521 break;
522 }
523 Show(native_show_state);
524 } 362 }
525 363
526 bool NativeWidgetWin::IsVisible() const { 364 bool NativeWidgetWin::IsVisible() const {
527 return message_handler_->IsVisible(); 365 return message_handler_->IsVisible();
528 } 366 }
529 367
530 void NativeWidgetWin::Activate() { 368 void NativeWidgetWin::Activate() {
531 message_handler_->Activate(); 369 message_handler_->Activate();
532 } 370 }
533 371
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 void NativeWidgetWin::SetInactiveRenderingDisabled(bool value) { 482 void NativeWidgetWin::SetInactiveRenderingDisabled(bool value) {
645 } 483 }
646 484
647 Widget::MoveLoopResult NativeWidgetWin::RunMoveLoop( 485 Widget::MoveLoopResult NativeWidgetWin::RunMoveLoop(
648 const gfx::Point& drag_offset) { 486 const gfx::Point& drag_offset) {
649 return message_handler_->RunMoveLoop(drag_offset) ? 487 return message_handler_->RunMoveLoop(drag_offset) ?
650 Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED; 488 Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED;
651 } 489 }
652 490
653 void NativeWidgetWin::EndMoveLoop() { 491 void NativeWidgetWin::EndMoveLoop() {
654 SendMessage(hwnd(), WM_CANCELMODE, 0, 0); 492 message_handler_->EndMoveLoop();
655 } 493 }
656 494
657 void NativeWidgetWin::SetVisibilityChangedAnimationsEnabled(bool value) { 495 void NativeWidgetWin::SetVisibilityChangedAnimationsEnabled(bool value) {
658 message_handler_->SetVisibilityChangedAnimationsEnabled(value); 496 message_handler_->SetVisibilityChangedAnimationsEnabled(value);
659 } 497 }
660 498
661 //////////////////////////////////////////////////////////////////////////////// 499 ////////////////////////////////////////////////////////////////////////////////
662 // NativeWidgetWin, MessageLoop::Observer implementation: 500 // NativeWidgetWin, MessageLoop::Observer implementation:
663 501
664 base::EventStatus NativeWidgetWin::WillProcessEvent( 502 base::EventStatus NativeWidgetWin::WillProcessEvent(
665 const base::NativeEvent& event) { 503 const base::NativeEvent& event) {
666 return base::EVENT_CONTINUE; 504 return base::EVENT_CONTINUE;
667 } 505 }
668 506
669 void NativeWidgetWin::DidProcessEvent(const base::NativeEvent& event) { 507 void NativeWidgetWin::DidProcessEvent(const base::NativeEvent& event) {
670 message_handler_->RedrawInvalidRect(); 508 message_handler_->RedrawInvalidRect();
671 } 509 }
672 510
673 //////////////////////////////////////////////////////////////////////////////// 511 ////////////////////////////////////////////////////////////////////////////////
674 // NativeWidgetWin, WindowImpl overrides: 512 // NativeWidgetWin, WindowImpl overrides:
675 513
676 HICON NativeWidgetWin::GetDefaultWindowIcon() const { 514 HICON NativeWidgetWin::GetDefaultWindowIcon() const {
677 if (ViewsDelegate::views_delegate) 515 return message_handler_->GetDefaultWindowIcon();
678 return ViewsDelegate::views_delegate->GetDefaultWindowIcon();
679 return NULL;
680 } 516 }
681 517
682 LRESULT NativeWidgetWin::OnWndProc(UINT message, 518 LRESULT NativeWidgetWin::OnWndProc(UINT message,
683 WPARAM w_param, 519 WPARAM w_param,
684 LPARAM l_param) { 520 LPARAM l_param) {
685 HWND window = hwnd(); 521 return message_handler_->OnWndProc(message, w_param, l_param);
686 LRESULT result = 0;
687
688 // First allow messages sent by child controls to be processed directly by
689 // their associated views. If such a view is present, it will handle the
690 // message *instead of* this NativeWidgetWin.
691 if (ProcessChildWindowMessage(message, w_param, l_param, &result))
692 return result;
693
694 // Otherwise we handle everything else.
695 if (!ProcessWindowMessage(window, message, w_param, l_param, result))
696 result = DefWindowProc(window, message, w_param, l_param);
697 if (message == WM_NCDESTROY) {
698 MessageLoopForUI::current()->RemoveObserver(this);
699 OnFinalMessage(window);
700 }
701
702 // Only top level widget should store/restore focus.
703 if (message == WM_ACTIVATE && GetWidget()->is_top_level())
704 PostProcessActivateMessage(this, LOWORD(w_param));
705 if (message == WM_ENABLE && restore_focus_when_enabled_) {
706 // This path should be executed only for top level as
707 // restore_focus_when_enabled_ is set in PostProcessActivateMessage.
708 DCHECK(GetWidget()->is_top_level());
709 restore_focus_when_enabled_ = false;
710 GetWidget()->GetFocusManager()->RestoreFocusedView();
711 }
712 return result;
713 } 522 }
714 523
715 //////////////////////////////////////////////////////////////////////////////// 524 ////////////////////////////////////////////////////////////////////////////////
716 // NativeWidgetWin, protected: 525 // NativeWidgetWin, protected:
717 526
718 // Message handlers ------------------------------------------------------------ 527 // Message handlers ------------------------------------------------------------
719 528
720 void NativeWidgetWin::OnActivate(UINT action, BOOL minimized, HWND window) { 529 void NativeWidgetWin::OnActivate(UINT action, BOOL minimized, HWND window) {
721 message_handler_->OnActivate(action, minimized, window); 530 message_handler_->OnActivate(action, minimized, window);
722 } 531 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 // WM_DESTROY that assume the properties are still valid (such as WM_CLOSE). 769 // WM_DESTROY that assume the properties are still valid (such as WM_CLOSE).
961 props_.clear(); 770 props_.clear();
962 delegate_->OnNativeWidgetDestroyed(); 771 delegate_->OnNativeWidgetDestroyed();
963 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 772 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
964 delete this; 773 delete this;
965 } 774 }
966 775
967 //////////////////////////////////////////////////////////////////////////////// 776 ////////////////////////////////////////////////////////////////////////////////
968 // NativeWidgetWin, protected: 777 // NativeWidgetWin, protected:
969 778
970 int NativeWidgetWin::GetShowState() const {
971 return SW_SHOWNORMAL;
972 }
973
974 void NativeWidgetWin::OnScreenReaderDetected() { 779 void NativeWidgetWin::OnScreenReaderDetected() {
975 screen_reader_active_ = true; 780 screen_reader_active_ = true;
976 } 781 }
977 782
978 void NativeWidgetWin::SetInitialFocus() {
979 if (!GetWidget()->SetInitialFocus() &&
980 !(GetWindowLong(GWL_EXSTYLE) & WS_EX_TRANSPARENT) &&
981 !(GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE)) {
982 // The window does not get keyboard messages unless we focus it.
983 SetFocus(GetNativeView());
984 }
985 }
986
987 //////////////////////////////////////////////////////////////////////////////// 783 ////////////////////////////////////////////////////////////////////////////////
988 // NativeWidgetWin, HWNDMessageHandlerDelegate implementation: 784 // NativeWidgetWin, HWNDMessageHandlerDelegate implementation:
989 785
990 bool NativeWidgetWin::IsWidgetWindow() const { 786 bool NativeWidgetWin::IsWidgetWindow() const {
991 // We don't NULL check GetWidget()->non_client_view() here because this 787 // We don't NULL check GetWidget()->non_client_view() here because this
992 // function can be called before the widget is fully constructed. 788 // function can be called before the widget is fully constructed.
993 return has_non_client_view_; 789 return has_non_client_view_;
994 } 790 }
995 791
996 bool NativeWidgetWin::IsUsingCustomFrame() const { 792 bool NativeWidgetWin::IsUsingCustomFrame() const {
(...skipping 17 matching lines...) Expand all
1014 } 810 }
1015 811
1016 bool NativeWidgetWin::CanMaximize() const { 812 bool NativeWidgetWin::CanMaximize() const {
1017 return GetWidget()->widget_delegate()->CanMaximize(); 813 return GetWidget()->widget_delegate()->CanMaximize();
1018 } 814 }
1019 815
1020 bool NativeWidgetWin::CanActivate() const { 816 bool NativeWidgetWin::CanActivate() const {
1021 return delegate_->CanActivate(); 817 return delegate_->CanActivate();
1022 } 818 }
1023 819
820 bool NativeWidgetWin::CanSaveFocus() const {
821 return GetWidget()->is_top_level();
822 }
823
824 void NativeWidgetWin::SaveFocusOnDeactivate() {
825 GetWidget()->GetFocusManager()->StoreFocusedView();
826 }
827
828 void NativeWidgetWin::RestoreFocusOnActivate() {
829 // Mysteriously, this only appears to be needed support restoration of focus
830 // to a child hwnd when restoring its top level window from the minimized
831 // state. If we don't do this, then ::SetFocus() to that child HWND returns
832 // ERROR_INVALID_PARAMETER, despite both HWNDs being of the same thread.
833 // See http://crbug.com/125976
834 {
835 // Since this is a synthetic reset, we don't need to tell anyone about it.
836 AutoNativeNotificationDisabler disabler;
837 GetWidget()->GetFocusManager()->ClearFocus();
838 }
839 RestoreFocusOnEnable();
840 }
841
842 void NativeWidgetWin::RestoreFocusOnEnable() {
843 GetWidget()->GetFocusManager()->RestoreFocusedView();
844 }
845
846 bool NativeWidgetWin::IsModal() const {
847 return delegate_->IsModal();
848 }
849
850 int NativeWidgetWin::GetInitialShowState() const {
851 return SW_SHOWNORMAL;
852 }
853
1024 bool NativeWidgetWin::WillProcessWorkAreaChange() const { 854 bool NativeWidgetWin::WillProcessWorkAreaChange() const {
1025 return GetWidget()->widget_delegate()->WillProcessWorkAreaChange(); 855 return GetWidget()->widget_delegate()->WillProcessWorkAreaChange();
1026 } 856 }
1027 857
1028 int NativeWidgetWin::GetNonClientComponent(const gfx::Point& point) const { 858 int NativeWidgetWin::GetNonClientComponent(const gfx::Point& point) const {
1029 return delegate_->GetNonClientComponent(point); 859 return delegate_->GetNonClientComponent(point);
1030 } 860 }
1031 861
1032 void NativeWidgetWin::GetWindowMask(const gfx::Size& size, gfx::Path* path) { 862 void NativeWidgetWin::GetWindowMask(const gfx::Size& size, gfx::Path* path) {
1033 if (GetWidget()->non_client_view()) 863 if (GetWidget()->non_client_view())
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 if (!tooltip_manager_->Init()) { 960 if (!tooltip_manager_->Init()) {
1131 // There was a problem creating the TooltipManager. Common error is 127. 961 // There was a problem creating the TooltipManager. Common error is 127.
1132 // See 82193 for details. 962 // See 82193 for details.
1133 LOG_GETLASTERROR(WARNING) << "tooltip creation failed, disabling tooltips"; 963 LOG_GETLASTERROR(WARNING) << "tooltip creation failed, disabling tooltips";
1134 tooltip_manager_.reset(); 964 tooltip_manager_.reset();
1135 } 965 }
1136 966
1137 delegate_->OnNativeWidgetCreated(); 967 delegate_->OnNativeWidgetCreated();
1138 } 968 }
1139 969
1140 void NativeWidgetWin::HandleDestroy() { 970 void NativeWidgetWin::HandleDestroying() {
1141 delegate_->OnNativeWidgetDestroying(); 971 delegate_->OnNativeWidgetDestroying();
1142 if (drop_target_.get()) { 972 if (drop_target_.get()) {
1143 RevokeDragDrop(hwnd()); 973 RevokeDragDrop(hwnd());
1144 drop_target_ = NULL; 974 drop_target_ = NULL;
1145 } 975 }
1146 } 976 }
1147 977
978 void NativeWidgetWin::HandleDestroyed() {
979 MessageLoopForUI::current()->RemoveObserver(this);
980 OnFinalMessage(hwnd());
981 }
982
983 bool NativeWidgetWin::HandleInitialFocus() {
984 return GetWidget()->SetInitialFocus();
985 }
986
1148 void NativeWidgetWin::HandleDisplayChange() { 987 void NativeWidgetWin::HandleDisplayChange() {
1149 GetWidget()->widget_delegate()->OnDisplayChanged(); 988 GetWidget()->widget_delegate()->OnDisplayChanged();
1150 } 989 }
1151 990
1152 void NativeWidgetWin::HandleGlassModeChange() { 991 void NativeWidgetWin::HandleGlassModeChange() {
1153 // For some reason, we need to hide the window while we're changing the frame 992 // For some reason, we need to hide the window while we're changing the frame
1154 // type only when we're changing it in response to WM_DWMCOMPOSITIONCHANGED. 993 // type only when we're changing it in response to WM_DWMCOMPOSITIONCHANGED.
1155 // If we don't, the client area will be filled with black. I'm suspecting 994 // If we don't, the client area will be filled with black. I'm suspecting
1156 // something skia-ey. 995 // something skia-ey.
1157 // Frame type toggling caused by the user (e.g. switching theme) doesn't seem 996 // Frame type toggling caused by the user (e.g. switching theme) doesn't seem
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 tooltip_manager_->OnMouse(message, w_param, l_param); 1072 tooltip_manager_->OnMouse(message, w_param, l_param);
1234 } 1073 }
1235 1074
1236 NativeWidgetWin* NativeWidgetWin::AsNativeWidgetWin() { 1075 NativeWidgetWin* NativeWidgetWin::AsNativeWidgetWin() {
1237 return this; 1076 return this;
1238 } 1077 }
1239 1078
1240 //////////////////////////////////////////////////////////////////////////////// 1079 ////////////////////////////////////////////////////////////////////////////////
1241 // NativeWidgetWin, private: 1080 // NativeWidgetWin, private:
1242 1081
1243 // static
1244 void NativeWidgetWin::PostProcessActivateMessage(NativeWidgetWin* widget,
1245 int activation_state) {
1246 DCHECK(widget->GetWidget()->is_top_level());
1247 FocusManager* focus_manager = widget->GetWidget()->GetFocusManager();
1248 if (WA_INACTIVE == activation_state) {
1249 // We might get activated/inactivated without being enabled, so we need to
1250 // clear restore_focus_when_enabled_.
1251 widget->restore_focus_when_enabled_ = false;
1252 focus_manager->StoreFocusedView();
1253 } else {
1254 // We must restore the focus after the message has been DefProc'ed as it
1255 // does set the focus to the last focused HWND.
1256 // Note that if the window is not enabled, we cannot restore the focus as
1257 // calling ::SetFocus on a child of the non-enabled top-window would fail.
1258 // This is the case when showing a modal dialog (such as 'open file',
1259 // 'print'...) from a different thread.
1260 // In that case we delay the focus restoration to when the window is enabled
1261 // again.
1262 if (!IsWindowEnabled(widget->GetNativeView())) {
1263 DCHECK(!widget->restore_focus_when_enabled_);
1264 widget->restore_focus_when_enabled_ = true;
1265 return;
1266 }
1267
1268 // Mysteriously, this only appears to be needed support restoration of focus
1269 // to a child hwnd when restoring its top level window from the minimized
1270 // state. If we don't do this, then ::SetFocus() to that child HWND returns
1271 // ERROR_INVALID_PARAMETER, despite both HWNDs being of the same thread.
1272 // See http://crbug.com/125976
1273 {
1274 // Since this is a synthetic reset, we don't need to tell anyone about it.
1275 AutoNativeNotificationDisabler disabler;
1276 focus_manager->ClearFocus();
1277 }
1278
1279 focus_manager->RestoreFocusedView();
1280 }
1281 }
1282
1283 void NativeWidgetWin::SetInitParams(const Widget::InitParams& params) { 1082 void NativeWidgetWin::SetInitParams(const Widget::InitParams& params) {
1284 // Set non-style attributes. 1083 // Set non-style attributes.
1285 ownership_ = params.ownership; 1084 ownership_ = params.ownership;
1286 1085
1287 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; 1086 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
1288 DWORD ex_style = 0; 1087 DWORD ex_style = 0;
1289 DWORD class_style = CS_DBLCLKS; 1088 DWORD class_style = CS_DBLCLKS;
1290 1089
1291 // Set type-independent style attributes. 1090 // Set type-independent style attributes.
1292 if (params.child) 1091 if (params.child)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 1166
1368 has_non_client_view_ = Widget::RequiresNonClientView(params.type); 1167 has_non_client_view_ = Widget::RequiresNonClientView(params.type);
1369 message_handler_->set_remove_standard_frame(params.remove_standard_frame); 1168 message_handler_->set_remove_standard_frame(params.remove_standard_frame);
1370 } 1169 }
1371 1170
1372 bool NativeWidgetWin::WidgetSizeIsClientSize() const { 1171 bool NativeWidgetWin::WidgetSizeIsClientSize() const {
1373 const Widget* widget = GetWidget()->GetTopLevelWidget(); 1172 const Widget* widget = GetWidget()->GetTopLevelWidget();
1374 return IsZoomed() || (widget && widget->ShouldUseNativeFrame()); 1173 return IsZoomed() || (widget && widget->ShouldUseNativeFrame());
1375 } 1174 }
1376 1175
1377 void NativeWidgetWin::RestoreEnabledIfNecessary() {
1378 if (delegate_->IsModal() && !restored_enabled_) {
1379 restored_enabled_ = true;
1380 // If we were run modally, we need to undo the disabled-ness we inflicted on
1381 // the owner's parent hierarchy.
1382 HWND start = ::GetWindow(GetNativeView(), GW_OWNER);
1383 while (start) {
1384 ::EnableWindow(start, TRUE);
1385 start = ::GetParent(start);
1386 }
1387 }
1388 }
1389
1390 //////////////////////////////////////////////////////////////////////////////// 1176 ////////////////////////////////////////////////////////////////////////////////
1391 // Widget, public: 1177 // Widget, public:
1392 1178
1393 // static 1179 // static
1394 void Widget::NotifyLocaleChanged() { 1180 void Widget::NotifyLocaleChanged() {
1395 NOTIMPLEMENTED(); 1181 NOTIMPLEMENTED();
1396 } 1182 }
1397 1183
1398 namespace { 1184 namespace {
1399 BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { 1185 BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 // static 1336 // static
1551 bool NativeWidgetPrivate::IsTouchDown() { 1337 bool NativeWidgetPrivate::IsTouchDown() {
1552 // This currently isn't necessary because we're not generating touch events on 1338 // This currently isn't necessary because we're not generating touch events on
1553 // windows. When we do, this will need to be updated. 1339 // windows. When we do, this will need to be updated.
1554 return false; 1340 return false;
1555 } 1341 }
1556 1342
1557 } // namespace internal 1343 } // namespace internal
1558 1344
1559 } // namespace views 1345 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_win.h ('k') | ui/views/win/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698