| OLD | NEW |
| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/win/scoped_gdi_object.h" | 14 #include "base/win/scoped_gdi_object.h" |
| 15 #include "base/win/win_util.h" | 15 #include "base/win/win_util.h" |
| 16 #include "base/win/windows_version.h" | 16 #include "base/win/windows_version.h" |
| 17 #include "ui/base/dragdrop/drag_drop_types.h" | 17 #include "ui/base/dragdrop/drag_drop_types.h" |
| 18 #include "ui/base/dragdrop/drag_source.h" | 18 #include "ui/base/dragdrop/drag_source.h" |
| 19 #include "ui/base/dragdrop/os_exchange_data.h" | 19 #include "ui/base/dragdrop/os_exchange_data.h" |
| 20 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 20 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
| 21 #include "ui/base/event.h" | 21 #include "ui/base/event.h" |
| 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/gfx/canvas.h" | 29 #include "ui/gfx/canvas.h" |
| 29 #include "ui/gfx/canvas_paint.h" | 30 #include "ui/gfx/canvas_paint.h" |
| 30 #include "ui/gfx/canvas_skia_paint.h" | 31 #include "ui/gfx/canvas_skia_paint.h" |
| 31 #include "ui/gfx/icon_util.h" | 32 #include "ui/gfx/icon_util.h" |
| 32 #include "ui/gfx/path.h" | 33 #include "ui/gfx/path.h" |
| 33 #include "ui/gfx/screen.h" | 34 #include "ui/gfx/screen.h" |
| 34 #include "ui/views/accessibility/native_view_accessibility_win.h" | 35 #include "ui/views/accessibility/native_view_accessibility_win.h" |
| 35 #include "ui/views/controls/native_control_win.h" | 36 #include "ui/views/controls/native_control_win.h" |
| 36 #include "ui/views/controls/textfield/native_textfield_views.h" | 37 #include "ui/views/controls/textfield/native_textfield_views.h" |
| 37 #include "ui/views/drag_utils.h" | 38 #include "ui/views/drag_utils.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 data->owned_widgets.push_back(widget); | 312 data->owned_widgets.push_back(widget); |
| 312 } | 313 } |
| 313 return TRUE; | 314 return TRUE; |
| 314 } | 315 } |
| 315 | 316 |
| 316 } // namespace | 317 } // namespace |
| 317 | 318 |
| 318 // static | 319 // static |
| 319 bool NativeWidgetWin::screen_reader_active_ = false; | 320 bool NativeWidgetWin::screen_reader_active_ = false; |
| 320 | 321 |
| 321 // A scoping class that prevents a window from being able to redraw in response | |
| 322 // to invalidations that may occur within it for the lifetime of the object. | |
| 323 // | |
| 324 // Why would we want such a thing? Well, it turns out Windows has some | |
| 325 // "unorthodox" behavior when it comes to painting its non-client areas. | |
| 326 // Occasionally, Windows will paint portions of the default non-client area | |
| 327 // right over the top of the custom frame. This is not simply fixed by handling | |
| 328 // WM_NCPAINT/WM_PAINT, with some investigation it turns out that this | |
| 329 // rendering is being done *inside* the default implementation of some message | |
| 330 // handlers and functions: | |
| 331 // . WM_SETTEXT | |
| 332 // . WM_SETICON | |
| 333 // . WM_NCLBUTTONDOWN | |
| 334 // . EnableMenuItem, called from our WM_INITMENU handler | |
| 335 // The solution is to handle these messages and call DefWindowProc ourselves, | |
| 336 // but prevent the window from being able to update itself for the duration of | |
| 337 // the call. We do this with this class, which automatically calls its | |
| 338 // associated Window's lock and unlock functions as it is created and destroyed. | |
| 339 // See documentation in those methods for the technique used. | |
| 340 // | |
| 341 // The lock only has an effect if the window was visible upon lock creation, as | |
| 342 // it doesn't guard against direct visiblility changes, and multiple locks may | |
| 343 // exist simultaneously to handle certain nested Windows messages. | |
| 344 // | |
| 345 // IMPORTANT: Do not use this scoping object for large scopes or periods of | |
| 346 // time! IT WILL PREVENT THE WINDOW FROM BEING REDRAWN! (duh). | |
| 347 // | |
| 348 // I would love to hear Raymond Chen's explanation for all this. And maybe a | |
| 349 // list of other messages that this applies to ;-) | |
| 350 class NativeWidgetWin::ScopedRedrawLock { | |
| 351 public: | |
| 352 explicit ScopedRedrawLock(NativeWidgetWin* widget) | |
| 353 : widget_(widget), | |
| 354 native_view_(widget_->GetNativeView()), | |
| 355 was_visible_(widget_->IsVisible()), | |
| 356 cancel_unlock_(false), | |
| 357 force_(!(widget_->GetWindowLong(GWL_STYLE) & WS_CAPTION)) { | |
| 358 if (was_visible_ && ::IsWindow(native_view_)) | |
| 359 widget_->LockUpdates(force_); | |
| 360 } | |
| 361 | |
| 362 ~ScopedRedrawLock() { | |
| 363 if (!cancel_unlock_ && was_visible_ && ::IsWindow(native_view_)) | |
| 364 widget_->UnlockUpdates(force_); | |
| 365 } | |
| 366 | |
| 367 // Cancel the unlock operation, call this if the Widget is being destroyed. | |
| 368 void CancelUnlockOperation() { cancel_unlock_ = true; } | |
| 369 | |
| 370 private: | |
| 371 // The widget having its style changed. | |
| 372 NativeWidgetWin* widget_; | |
| 373 // The widget's native view, cached to avoid action after window destruction. | |
| 374 gfx::NativeView native_view_; | |
| 375 // Records the widget visibility at the time of creation. | |
| 376 bool was_visible_; | |
| 377 // A flag indicating that the unlock operation was canceled. | |
| 378 bool cancel_unlock_; | |
| 379 // If true, perform the redraw lock regardless of Aero state. | |
| 380 bool force_; | |
| 381 }; | |
| 382 | |
| 383 //////////////////////////////////////////////////////////////////////////////// | 322 //////////////////////////////////////////////////////////////////////////////// |
| 384 // NativeWidgetWin, public: | 323 // NativeWidgetWin, public: |
| 385 | 324 |
| 386 NativeWidgetWin::NativeWidgetWin(internal::NativeWidgetDelegate* delegate) | 325 NativeWidgetWin::NativeWidgetWin(internal::NativeWidgetDelegate* delegate) |
| 387 : delegate_(delegate), | 326 : delegate_(delegate), |
| 388 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 327 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
| 389 active_mouse_tracking_flags_(0), | |
| 390 use_layered_buffer_(false), | 328 use_layered_buffer_(false), |
| 391 layered_alpha_(255), | 329 layered_alpha_(255), |
| 392 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), | 330 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), |
| 393 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 331 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
| 394 can_update_layered_window_(true), | 332 can_update_layered_window_(true), |
| 395 restore_focus_when_enabled_(false), | 333 restore_focus_when_enabled_(false), |
| 396 accessibility_view_events_index_(-1), | 334 accessibility_view_events_index_(-1), |
| 397 accessibility_view_events_(kMaxAccessibilityViewEvents), | 335 accessibility_view_events_(kMaxAccessibilityViewEvents), |
| 398 previous_cursor_(NULL), | 336 previous_cursor_(NULL), |
| 399 fullscreen_(false), | 337 fullscreen_(false), |
| 400 metro_snap_(false), | 338 metro_snap_(false), |
| 401 force_hidden_count_(0), | 339 force_hidden_count_(0), |
| 402 lock_updates_count_(0), | |
| 403 ignore_window_pos_changes_(false), | 340 ignore_window_pos_changes_(false), |
| 404 ALLOW_THIS_IN_INITIALIZER_LIST(ignore_pos_changes_factory_(this)), | 341 ALLOW_THIS_IN_INITIALIZER_LIST(ignore_pos_changes_factory_(this)), |
| 405 last_monitor_(NULL), | 342 last_monitor_(NULL), |
| 406 is_right_mouse_pressed_on_caption_(false), | |
| 407 restored_enabled_(false), | 343 restored_enabled_(false), |
| 408 destroyed_(NULL), | |
| 409 has_non_client_view_(false), | 344 has_non_client_view_(false), |
| 410 ALLOW_THIS_IN_INITIALIZER_LIST( | 345 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 411 message_handler_(new HWNDMessageHandler(this))) { | 346 message_handler_(new HWNDMessageHandler(this))) { |
| 412 } | 347 } |
| 413 | 348 |
| 414 NativeWidgetWin::~NativeWidgetWin() { | 349 NativeWidgetWin::~NativeWidgetWin() { |
| 415 if (destroyed_ != NULL) | |
| 416 *destroyed_ = true; | |
| 417 | |
| 418 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 350 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| 419 delete delegate_; | 351 delete delegate_; |
| 420 else | 352 else |
| 421 CloseNow(); | 353 CloseNow(); |
| 422 } | 354 } |
| 423 | 355 |
| 424 // static | 356 // static |
| 425 bool NativeWidgetWin::IsAeroGlassEnabled() { | |
| 426 if (base::win::GetVersion() < base::win::VERSION_VISTA) | |
| 427 return false; | |
| 428 // If composition is not enabled, we behave like on XP. | |
| 429 BOOL enabled = FALSE; | |
| 430 return SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled; | |
| 431 } | |
| 432 | |
| 433 // static | |
| 434 gfx::Font NativeWidgetWin::GetWindowTitleFont() { | 357 gfx::Font NativeWidgetWin::GetWindowTitleFont() { |
| 435 NONCLIENTMETRICS ncm; | 358 NONCLIENTMETRICS ncm; |
| 436 base::win::GetNonClientMetrics(&ncm); | 359 base::win::GetNonClientMetrics(&ncm); |
| 437 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); | 360 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); |
| 438 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); | 361 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); |
| 439 return gfx::Font(caption_font); | 362 return gfx::Font(caption_font); |
| 440 } | 363 } |
| 441 | 364 |
| 442 void NativeWidgetWin::Show(int show_state) { | 365 void NativeWidgetWin::Show(int show_state) { |
| 443 ShowWindow(show_state); | 366 ShowWindow(show_state); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 return GetWidget()->ShouldUseNativeFrame() ? | 442 return GetWidget()->ShouldUseNativeFrame() ? |
| 520 new NativeFrameView(GetWidget()) : NULL; | 443 new NativeFrameView(GetWidget()) : NULL; |
| 521 } | 444 } |
| 522 | 445 |
| 523 void NativeWidgetWin::UpdateFrameAfterFrameChange() { | 446 void NativeWidgetWin::UpdateFrameAfterFrameChange() { |
| 524 // We've either gained or lost a custom window region, so reset it now. | 447 // We've either gained or lost a custom window region, so reset it now. |
| 525 message_handler_->ResetWindowRegion(true); | 448 message_handler_->ResetWindowRegion(true); |
| 526 } | 449 } |
| 527 | 450 |
| 528 bool NativeWidgetWin::ShouldUseNativeFrame() const { | 451 bool NativeWidgetWin::ShouldUseNativeFrame() const { |
| 529 return IsAeroGlassEnabled(); | 452 return ui::win::IsAeroGlassEnabled(); |
| 530 } | 453 } |
| 531 | 454 |
| 532 void NativeWidgetWin::FrameTypeChanged() { | 455 void NativeWidgetWin::FrameTypeChanged() { |
| 533 // Called when the frame type could possibly be changing (theme change or | 456 // Called when the frame type could possibly be changing (theme change or |
| 534 // DWM composition change). | 457 // DWM composition change). |
| 535 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 458 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 536 // We need to toggle the rendering policy of the DWM/glass frame as we | 459 // We need to toggle the rendering policy of the DWM/glass frame as we |
| 537 // change from opaque to glass. "Non client rendering enabled" means that | 460 // change from opaque to glass. "Non client rendering enabled" means that |
| 538 // the DWM's glass non-client rendering is enabled, which is why | 461 // the DWM's glass non-client rendering is enabled, which is why |
| 539 // DWMNCRP_ENABLED is used for the native frame case. _DISABLED means the | 462 // DWMNCRP_ENABLED is used for the native frame case. _DISABLED means the |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 // event. The widget gives us a temporary unique child ID to associate | 554 // event. The widget gives us a temporary unique child ID to associate |
| 632 // with this view so that clients can call get_accChild in | 555 // with this view so that clients can call get_accChild in |
| 633 // NativeViewAccessibilityWin to retrieve the IAccessible associated | 556 // NativeViewAccessibilityWin to retrieve the IAccessible associated |
| 634 // with this view. | 557 // with this view. |
| 635 int child_id = AddAccessibilityViewEvent(view); | 558 int child_id = AddAccessibilityViewEvent(view); |
| 636 ::NotifyWinEvent(NativeViewAccessibilityWin::MSAAEvent(event_type), | 559 ::NotifyWinEvent(NativeViewAccessibilityWin::MSAAEvent(event_type), |
| 637 GetNativeView(), OBJID_CLIENT, child_id); | 560 GetNativeView(), OBJID_CLIENT, child_id); |
| 638 } | 561 } |
| 639 | 562 |
| 640 void NativeWidgetWin::SetCapture() { | 563 void NativeWidgetWin::SetCapture() { |
| 641 DCHECK(!HasCapture()); | 564 message_handler_->SetCapture(); |
| 642 ::SetCapture(hwnd()); | |
| 643 } | 565 } |
| 644 | 566 |
| 645 void NativeWidgetWin::ReleaseCapture() { | 567 void NativeWidgetWin::ReleaseCapture() { |
| 646 ::ReleaseCapture(); | 568 message_handler_->ReleaseCapture(); |
| 647 } | 569 } |
| 648 | 570 |
| 649 bool NativeWidgetWin::HasCapture() const { | 571 bool NativeWidgetWin::HasCapture() const { |
| 650 return ::GetCapture() == hwnd(); | 572 return message_handler_->HasCapture(); |
| 651 } | 573 } |
| 652 | 574 |
| 653 InputMethod* NativeWidgetWin::CreateInputMethod() { | 575 InputMethod* NativeWidgetWin::CreateInputMethod() { |
| 654 #if !defined(USE_AURA) | 576 return message_handler_->CreateInputMethod(); |
| 655 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 577 } |
| 656 if (!command_line->HasSwitch(switches::kEnableViewsTextfield)) | 578 |
| 657 return NULL; | 579 internal::InputMethodDelegate* NativeWidgetWin::GetInputMethodDelegate() { |
| 658 #endif | 580 return message_handler_.get(); |
| 659 InputMethod* input_method = new InputMethodWin(this); | |
| 660 input_method->Init(GetWidget()); | |
| 661 return input_method; | |
| 662 } | 581 } |
| 663 | 582 |
| 664 void NativeWidgetWin::CenterWindow(const gfx::Size& size) { | 583 void NativeWidgetWin::CenterWindow(const gfx::Size& size) { |
| 665 HWND parent = GetParent(); | 584 HWND parent = GetParent(); |
| 666 if (!IsWindow()) | 585 if (!IsWindow()) |
| 667 parent = ::GetWindow(GetNativeView(), GW_OWNER); | 586 parent = ::GetWindow(GetNativeView(), GW_OWNER); |
| 668 ui::CenterAndSizeWindow(parent, GetNativeView(), size); | 587 ui::CenterAndSizeWindow(parent, GetNativeView(), size); |
| 669 } | 588 } |
| 670 | 589 |
| 671 void NativeWidgetWin::GetWindowPlacement( | 590 void NativeWidgetWin::GetWindowPlacement( |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 ExecuteSystemMenuCommand(SC_MAXIMIZE); | 867 ExecuteSystemMenuCommand(SC_MAXIMIZE); |
| 949 } | 868 } |
| 950 | 869 |
| 951 void NativeWidgetWin::Minimize() { | 870 void NativeWidgetWin::Minimize() { |
| 952 ExecuteSystemMenuCommand(SC_MINIMIZE); | 871 ExecuteSystemMenuCommand(SC_MINIMIZE); |
| 953 | 872 |
| 954 delegate_->OnNativeBlur(NULL); | 873 delegate_->OnNativeBlur(NULL); |
| 955 } | 874 } |
| 956 | 875 |
| 957 bool NativeWidgetWin::IsMaximized() const { | 876 bool NativeWidgetWin::IsMaximized() const { |
| 958 return !!::IsZoomed(GetNativeView()); | 877 return message_handler_->IsMaximized(); |
| 959 } | 878 } |
| 960 | 879 |
| 961 bool NativeWidgetWin::IsMinimized() const { | 880 bool NativeWidgetWin::IsMinimized() const { |
| 962 return !!::IsIconic(GetNativeView()); | 881 return message_handler_->IsMinimized(); |
| 963 } | 882 } |
| 964 | 883 |
| 965 void NativeWidgetWin::Restore() { | 884 void NativeWidgetWin::Restore() { |
| 966 ExecuteSystemMenuCommand(SC_RESTORE); | 885 ExecuteSystemMenuCommand(SC_RESTORE); |
| 967 } | 886 } |
| 968 | 887 |
| 969 void NativeWidgetWin::SetFullscreen(bool fullscreen) { | 888 void NativeWidgetWin::SetFullscreen(bool fullscreen) { |
| 970 if (fullscreen_ == fullscreen) | 889 if (fullscreen_ == fullscreen) |
| 971 return; | 890 return; |
| 972 | 891 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 message_handler_->OnClose(); | 1182 message_handler_->OnClose(); |
| 1264 } | 1183 } |
| 1265 | 1184 |
| 1266 void NativeWidgetWin::OnCommand(UINT notification_code, | 1185 void NativeWidgetWin::OnCommand(UINT notification_code, |
| 1267 int command_id, | 1186 int command_id, |
| 1268 HWND window) { | 1187 HWND window) { |
| 1269 message_handler_->OnCommand(notification_code, command_id, window); | 1188 message_handler_->OnCommand(notification_code, command_id, window); |
| 1270 } | 1189 } |
| 1271 | 1190 |
| 1272 LRESULT NativeWidgetWin::OnCreate(CREATESTRUCT* create_struct) { | 1191 LRESULT NativeWidgetWin::OnCreate(CREATESTRUCT* create_struct) { |
| 1192 // TODO(beng): move to message_handler_. Needed before |
| 1193 // ClientAreaSizeChanged(). |
| 1194 use_layered_buffer_ = !!(window_ex_style() & WS_EX_LAYERED); |
| 1273 return message_handler_->OnCreate(create_struct); | 1195 return message_handler_->OnCreate(create_struct); |
| 1274 } | 1196 } |
| 1275 | 1197 |
| 1276 void NativeWidgetWin::OnDestroy() { | 1198 void NativeWidgetWin::OnDestroy() { |
| 1277 message_handler_->OnDestroy(); | 1199 message_handler_->OnDestroy(); |
| 1278 } | 1200 } |
| 1279 | 1201 |
| 1280 void NativeWidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) { | 1202 void NativeWidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) { |
| 1281 message_handler_->OnDisplayChange(bits_per_pixel, screen_size); | 1203 message_handler_->OnDisplayChange(bits_per_pixel, screen_size); |
| 1282 } | 1204 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 | 1278 |
| 1357 LRESULT NativeWidgetWin::OnMouseActivate(UINT message, | 1279 LRESULT NativeWidgetWin::OnMouseActivate(UINT message, |
| 1358 WPARAM w_param, | 1280 WPARAM w_param, |
| 1359 LPARAM l_param) { | 1281 LPARAM l_param) { |
| 1360 return message_handler_->OnMouseActivate(message, w_param, l_param); | 1282 return message_handler_->OnMouseActivate(message, w_param, l_param); |
| 1361 } | 1283 } |
| 1362 | 1284 |
| 1363 LRESULT NativeWidgetWin::OnMouseRange(UINT message, | 1285 LRESULT NativeWidgetWin::OnMouseRange(UINT message, |
| 1364 WPARAM w_param, | 1286 WPARAM w_param, |
| 1365 LPARAM l_param) { | 1287 LPARAM l_param) { |
| 1366 if (message == WM_RBUTTONUP && is_right_mouse_pressed_on_caption_) { | 1288 return message_handler_->OnMouseRange(message, w_param, l_param); |
| 1367 is_right_mouse_pressed_on_caption_ = false; | |
| 1368 ReleaseCapture(); | |
| 1369 // |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu() | |
| 1370 // expect screen coordinates. | |
| 1371 CPoint screen_point(l_param); | |
| 1372 MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_point, 1); | |
| 1373 w_param = SendMessage(GetNativeView(), WM_NCHITTEST, 0, | |
| 1374 MAKELPARAM(screen_point.x, screen_point.y)); | |
| 1375 if (w_param == HTCAPTION || w_param == HTSYSMENU) { | |
| 1376 ui::ShowSystemMenu(GetNativeView(), screen_point.x, screen_point.y); | |
| 1377 return 0; | |
| 1378 } | |
| 1379 } else if (message == WM_NCLBUTTONDOWN && | |
| 1380 !GetWidget()->ShouldUseNativeFrame()) { | |
| 1381 switch (w_param) { | |
| 1382 case HTCLOSE: | |
| 1383 case HTMINBUTTON: | |
| 1384 case HTMAXBUTTON: { | |
| 1385 // When the mouse is pressed down in these specific non-client areas, | |
| 1386 // we need to tell the RootView to send the mouse pressed event (which | |
| 1387 // sets capture, allowing subsequent WM_LBUTTONUP (note, _not_ | |
| 1388 // WM_NCLBUTTONUP) to fire so that the appropriate WM_SYSCOMMAND can be | |
| 1389 // sent by the applicable button's ButtonListener. We _have_ to do this | |
| 1390 // way rather than letting Windows just send the syscommand itself (as | |
| 1391 // would happen if we never did this dance) because for some insane | |
| 1392 // reason DefWindowProc for WM_NCLBUTTONDOWN also renders the pressed | |
| 1393 // window control button appearance, in the Windows classic style, over | |
| 1394 // our view! Ick! By handling this message we prevent Windows from | |
| 1395 // doing this undesirable thing, but that means we need to roll the | |
| 1396 // sys-command handling ourselves. | |
| 1397 // Combine |w_param| with common key state message flags. | |
| 1398 w_param |= base::win::IsCtrlPressed() ? MK_CONTROL : 0; | |
| 1399 w_param |= base::win::IsShiftPressed() ? MK_SHIFT : 0; | |
| 1400 } | |
| 1401 } | |
| 1402 } else if (message == WM_NCRBUTTONDOWN && | |
| 1403 (w_param == HTCAPTION || w_param == HTSYSMENU)) { | |
| 1404 is_right_mouse_pressed_on_caption_ = true; | |
| 1405 // We SetCapture() to ensure we only show the menu when the button | |
| 1406 // down and up are both on the caption. Note: this causes the button up to | |
| 1407 // be WM_RBUTTONUP instead of WM_NCRBUTTONUP. | |
| 1408 SetCapture(); | |
| 1409 } | |
| 1410 | |
| 1411 MSG msg = { hwnd(), message, w_param, l_param, 0, | |
| 1412 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; | |
| 1413 ui::MouseEvent event(msg); | |
| 1414 if (!touch_ids_.empty() || ui::IsMouseEventFromTouch(message)) | |
| 1415 event.set_flags(event.flags() | ui::EF_FROM_TOUCH); | |
| 1416 | |
| 1417 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) | |
| 1418 if (tooltip_manager_.get()) | |
| 1419 tooltip_manager_->OnMouse(message, w_param, l_param); | |
| 1420 | |
| 1421 if (event.type() == ui::ET_MOUSE_MOVED && !HasCapture()) { | |
| 1422 // Windows only fires WM_MOUSELEAVE events if the application begins | |
| 1423 // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events. | |
| 1424 // We need to call |TrackMouseEvents| to listen for WM_MOUSELEAVE. | |
| 1425 TrackMouseEvents((message == WM_NCMOUSEMOVE) ? | |
| 1426 TME_NONCLIENT | TME_LEAVE : TME_LEAVE); | |
| 1427 } else if (event.type() == ui::ET_MOUSE_EXITED) { | |
| 1428 // Reset our tracking flags so future mouse movement over this | |
| 1429 // NativeWidgetWin results in a new tracking session. Fall through for | |
| 1430 // OnMouseEvent. | |
| 1431 active_mouse_tracking_flags_ = 0; | |
| 1432 } else if (event.type() == ui::ET_MOUSEWHEEL) { | |
| 1433 // Reroute the mouse wheel to the window under the pointer if applicable. | |
| 1434 return (ui::RerouteMouseWheel(hwnd(), w_param, l_param) || | |
| 1435 delegate_->OnMouseEvent(ui::MouseWheelEvent(msg))) ? 0 : 1; | |
| 1436 } | |
| 1437 | |
| 1438 bool handled = delegate_->OnMouseEvent(event); | |
| 1439 | |
| 1440 if (!handled && message == WM_NCLBUTTONDOWN && w_param != HTSYSMENU && | |
| 1441 !GetWidget()->ShouldUseNativeFrame()) { | |
| 1442 // TODO(msw): Eliminate undesired painting, or re-evaluate this workaround. | |
| 1443 // DefWindowProc for WM_NCLBUTTONDOWN does weird non-client painting, so we | |
| 1444 // need to call it inside a ScopedRedrawLock. This may cause other negative | |
| 1445 // side-effects (ex/ stifling non-client mouse releases). | |
| 1446 DefWindowProcWithRedrawLock(message, w_param, l_param); | |
| 1447 handled = true; | |
| 1448 } | |
| 1449 | |
| 1450 SetMsgHandled(handled); | |
| 1451 return 0; | |
| 1452 } | 1289 } |
| 1453 | 1290 |
| 1454 void NativeWidgetWin::OnMove(const CPoint& point) { | 1291 void NativeWidgetWin::OnMove(const CPoint& point) { |
| 1455 message_handler_->OnMove(point); | 1292 message_handler_->OnMove(point); |
| 1456 } | 1293 } |
| 1457 | 1294 |
| 1458 void NativeWidgetWin::OnMoving(UINT param, const LPRECT new_bounds) { | 1295 void NativeWidgetWin::OnMoving(UINT param, const LPRECT new_bounds) { |
| 1459 message_handler_->OnMoving(param, new_bounds); | 1296 message_handler_->OnMoving(param, new_bounds); |
| 1460 } | 1297 } |
| 1461 | 1298 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1756 } | 1593 } |
| 1757 } | 1594 } |
| 1758 | 1595 |
| 1759 void NativeWidgetWin::OnThemeChanged() { | 1596 void NativeWidgetWin::OnThemeChanged() { |
| 1760 message_handler_->OnThemeChanged(); | 1597 message_handler_->OnThemeChanged(); |
| 1761 } | 1598 } |
| 1762 | 1599 |
| 1763 LRESULT NativeWidgetWin::OnTouchEvent(UINT message, | 1600 LRESULT NativeWidgetWin::OnTouchEvent(UINT message, |
| 1764 WPARAM w_param, | 1601 WPARAM w_param, |
| 1765 LPARAM l_param) { | 1602 LPARAM l_param) { |
| 1766 int num_points = LOWORD(w_param); | 1603 return message_handler_->OnTouchEvent(message, w_param, l_param); |
| 1767 scoped_array<TOUCHINPUT> input(new TOUCHINPUT[num_points]); | |
| 1768 if (GetTouchInputInfo(reinterpret_cast<HTOUCHINPUT>(l_param), | |
| 1769 num_points, input.get(), sizeof(TOUCHINPUT))) { | |
| 1770 for (int i = 0; i < num_points; ++i) { | |
| 1771 if (input[i].dwFlags & TOUCHEVENTF_DOWN) | |
| 1772 touch_ids_.insert(input[i].dwID); | |
| 1773 if (input[i].dwFlags & TOUCHEVENTF_UP) | |
| 1774 touch_ids_.erase(input[i].dwID); | |
| 1775 } | |
| 1776 } | |
| 1777 CloseTouchInputHandle(reinterpret_cast<HTOUCHINPUT>(l_param)); | |
| 1778 SetMsgHandled(FALSE); | |
| 1779 return 0; | |
| 1780 } | 1604 } |
| 1781 | 1605 |
| 1782 void NativeWidgetWin::OnVScroll(int scroll_type, | 1606 void NativeWidgetWin::OnVScroll(int scroll_type, |
| 1783 short position, | 1607 short position, |
| 1784 HWND scrollbar) { | 1608 HWND scrollbar) { |
| 1785 message_handler_->OnVScroll(scroll_type, position, scrollbar); | 1609 message_handler_->OnVScroll(scroll_type, position, scrollbar); |
| 1786 } | 1610 } |
| 1787 | 1611 |
| 1788 void NativeWidgetWin::OnWindowPosChanging(WINDOWPOS* window_pos) { | 1612 void NativeWidgetWin::OnWindowPosChanging(WINDOWPOS* window_pos) { |
| 1789 if (ignore_window_pos_changes_) { | 1613 if (ignore_window_pos_changes_) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1864 reinterpret_cast<LPARAM>(window_pos)); | 1688 reinterpret_cast<LPARAM>(window_pos)); |
| 1865 window_pos->cy = old_cy; | 1689 window_pos->cy = old_cy; |
| 1866 SetMsgHandled(TRUE); | 1690 SetMsgHandled(TRUE); |
| 1867 return; | 1691 return; |
| 1868 } | 1692 } |
| 1869 | 1693 |
| 1870 SetMsgHandled(FALSE); | 1694 SetMsgHandled(FALSE); |
| 1871 } | 1695 } |
| 1872 | 1696 |
| 1873 void NativeWidgetWin::OnWindowPosChanged(WINDOWPOS* window_pos) { | 1697 void NativeWidgetWin::OnWindowPosChanged(WINDOWPOS* window_pos) { |
| 1874 if (DidClientAreaSizeChange(window_pos)) | 1698 message_handler_->OnWindowPosChanged(window_pos); |
| 1875 ClientAreaSizeChanged(); | |
| 1876 if (message_handler_->remove_standard_frame() && | |
| 1877 window_pos->flags & SWP_FRAMECHANGED && | |
| 1878 IsAeroGlassEnabled()) { | |
| 1879 UpdateDWMFrame(); | |
| 1880 } | |
| 1881 if (window_pos->flags & SWP_SHOWWINDOW) | |
| 1882 delegate_->OnNativeWidgetVisibilityChanged(true); | |
| 1883 else if (window_pos->flags & SWP_HIDEWINDOW) | |
| 1884 delegate_->OnNativeWidgetVisibilityChanged(false); | |
| 1885 SetMsgHandled(FALSE); | |
| 1886 } | 1699 } |
| 1887 | 1700 |
| 1888 void NativeWidgetWin::OnFinalMessage(HWND window) { | 1701 void NativeWidgetWin::OnFinalMessage(HWND window) { |
| 1889 // We don't destroy props in WM_DESTROY as we may still get messages after | 1702 // We don't destroy props in WM_DESTROY as we may still get messages after |
| 1890 // WM_DESTROY that assume the properties are still valid (such as WM_CLOSE). | 1703 // WM_DESTROY that assume the properties are still valid (such as WM_CLOSE). |
| 1891 props_.clear(); | 1704 props_.clear(); |
| 1892 delegate_->OnNativeWidgetDestroyed(); | 1705 delegate_->OnNativeWidgetDestroyed(); |
| 1893 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 1706 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| 1894 delete this; | 1707 delete this; |
| 1895 } | 1708 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1928 // know why) the client area goes from matching the window rect to being | 1741 // know why) the client area goes from matching the window rect to being |
| 1929 // something else. If the client area is not the window rect in both | 1742 // something else. If the client area is not the window rect in both |
| 1930 // modes, the blackness doesn't occur. Because of this, we need to tell | 1743 // modes, the blackness doesn't occur. Because of this, we need to tell |
| 1931 // the RootView to lay out to fit the window rect, rather than the client | 1744 // the RootView to lay out to fit the window rect, rather than the client |
| 1932 // rect when using the opaque frame. | 1745 // rect when using the opaque frame. |
| 1933 // Note: this is only required for non-fullscreen windows. Note that | 1746 // Note: this is only required for non-fullscreen windows. Note that |
| 1934 // fullscreen windows are in restored state, not maximized. | 1747 // fullscreen windows are in restored state, not maximized. |
| 1935 return gfx::Insets(0, 0, IsFullscreen() ? 0 : 1, 0); | 1748 return gfx::Insets(0, 0, IsFullscreen() ? 0 : 1, 0); |
| 1936 } | 1749 } |
| 1937 | 1750 |
| 1938 void NativeWidgetWin::TrackMouseEvents(DWORD mouse_tracking_flags) { | |
| 1939 // Begin tracking mouse events for this HWND so that we get WM_MOUSELEAVE | |
| 1940 // when the user moves the mouse outside this HWND's bounds. | |
| 1941 if (active_mouse_tracking_flags_ == 0 || mouse_tracking_flags & TME_CANCEL) { | |
| 1942 if (mouse_tracking_flags & TME_CANCEL) { | |
| 1943 // We're about to cancel active mouse tracking, so empty out the stored | |
| 1944 // state. | |
| 1945 active_mouse_tracking_flags_ = 0; | |
| 1946 } else { | |
| 1947 active_mouse_tracking_flags_ = mouse_tracking_flags; | |
| 1948 } | |
| 1949 | |
| 1950 TRACKMOUSEEVENT tme; | |
| 1951 tme.cbSize = sizeof(tme); | |
| 1952 tme.dwFlags = mouse_tracking_flags; | |
| 1953 tme.hwndTrack = hwnd(); | |
| 1954 tme.dwHoverTime = 0; | |
| 1955 TrackMouseEvent(&tme); | |
| 1956 } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { | |
| 1957 TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); | |
| 1958 TrackMouseEvents(mouse_tracking_flags); | |
| 1959 } | |
| 1960 } | |
| 1961 | |
| 1962 void NativeWidgetWin::OnScreenReaderDetected() { | 1751 void NativeWidgetWin::OnScreenReaderDetected() { |
| 1963 screen_reader_active_ = true; | 1752 screen_reader_active_ = true; |
| 1964 } | 1753 } |
| 1965 | 1754 |
| 1966 void NativeWidgetWin::SetInitialFocus() { | 1755 void NativeWidgetWin::SetInitialFocus() { |
| 1967 if (!GetWidget()->SetInitialFocus() && | 1756 if (!GetWidget()->SetInitialFocus() && |
| 1968 !(GetWindowLong(GWL_EXSTYLE) & WS_EX_TRANSPARENT) && | 1757 !(GetWindowLong(GWL_EXSTYLE) & WS_EX_TRANSPARENT) && |
| 1969 !(GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE)) { | 1758 !(GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE)) { |
| 1970 // The window does not get keyboard messages unless we focus it. | 1759 // The window does not get keyboard messages unless we focus it. |
| 1971 SetFocus(GetNativeView()); | 1760 SetFocus(GetNativeView()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2066 bool NativeWidgetWin::HandleCommand(int command) { | 1855 bool NativeWidgetWin::HandleCommand(int command) { |
| 2067 return GetWidget()->widget_delegate()->ExecuteWindowsCommand(command); | 1856 return GetWidget()->widget_delegate()->ExecuteWindowsCommand(command); |
| 2068 } | 1857 } |
| 2069 | 1858 |
| 2070 void NativeWidgetWin::HandleCreate() { | 1859 void NativeWidgetWin::HandleCreate() { |
| 2071 // TODO(beng): much of this could/should maybe move to HWNDMessageHandler. | 1860 // TODO(beng): much of this could/should maybe move to HWNDMessageHandler. |
| 2072 | 1861 |
| 2073 SetNativeWindowProperty(kNativeWidgetKey, this); | 1862 SetNativeWindowProperty(kNativeWidgetKey, this); |
| 2074 CHECK_EQ(this, GetNativeWidgetForNativeView(hwnd())); | 1863 CHECK_EQ(this, GetNativeWidgetForNativeView(hwnd())); |
| 2075 | 1864 |
| 2076 use_layered_buffer_ = !!(window_ex_style() & WS_EX_LAYERED); | |
| 2077 | |
| 2078 props_.push_back(ui::SetWindowSupportsRerouteMouseWheel(hwnd())); | 1865 props_.push_back(ui::SetWindowSupportsRerouteMouseWheel(hwnd())); |
| 2079 | 1866 |
| 2080 drop_target_ = new DropTargetWin( | 1867 drop_target_ = new DropTargetWin( |
| 2081 static_cast<internal::RootView*>(GetWidget()->GetRootView())); | 1868 static_cast<internal::RootView*>(GetWidget()->GetRootView())); |
| 2082 | 1869 |
| 2083 // We need to add ourselves as a message loop observer so that we can repaint | 1870 // We need to add ourselves as a message loop observer so that we can repaint |
| 2084 // aggressively if the contents of our window become invalid. Unfortunately | 1871 // aggressively if the contents of our window become invalid. Unfortunately |
| 2085 // WM_PAINT messages are starved and we get flickery redrawing when resizing | 1872 // WM_PAINT messages are starved and we get flickery redrawing when resizing |
| 2086 // if we do not do this. | 1873 // if we do not do this. |
| 2087 MessageLoopForUI::current()->AddObserver(this); | 1874 MessageLoopForUI::current()->AddObserver(this); |
| 2088 | 1875 |
| 2089 // Windows special DWM window frame requires a special tooltip manager so | 1876 // Windows special DWM window frame requires a special tooltip manager so |
| 2090 // that window controls in Chrome windows don't flicker when you move your | 1877 // that window controls in Chrome windows don't flicker when you move your |
| 2091 // mouse over them. See comment in aero_tooltip_manager.h. | 1878 // mouse over them. See comment in aero_tooltip_manager.h. |
| 2092 Widget* widget = GetWidget()->GetTopLevelWidget(); | 1879 Widget* widget = GetWidget()->GetTopLevelWidget(); |
| 2093 if (widget && widget->ShouldUseNativeFrame()) { | 1880 if (widget && widget->ShouldUseNativeFrame()) { |
| 2094 tooltip_manager_.reset(new AeroTooltipManager(GetWidget())); | 1881 tooltip_manager_.reset(new AeroTooltipManager(GetWidget())); |
| 2095 } else { | 1882 } else { |
| 2096 tooltip_manager_.reset(new TooltipManagerWin(GetWidget())); | 1883 tooltip_manager_.reset(new TooltipManagerWin(GetWidget())); |
| 2097 } | 1884 } |
| 2098 if (!tooltip_manager_->Init()) { | 1885 if (!tooltip_manager_->Init()) { |
| 2099 // There was a problem creating the TooltipManager. Common error is 127. | 1886 // There was a problem creating the TooltipManager. Common error is 127. |
| 2100 // See 82193 for details. | 1887 // See 82193 for details. |
| 2101 LOG_GETLASTERROR(WARNING) << "tooltip creation failed, disabling tooltips"; | 1888 LOG_GETLASTERROR(WARNING) << "tooltip creation failed, disabling tooltips"; |
| 2102 tooltip_manager_.reset(); | 1889 tooltip_manager_.reset(); |
| 2103 } | 1890 } |
| 2104 | 1891 |
| 2105 // We need to allow the delegate to size its contents since the window may not | |
| 2106 // receive a size notification when its initial bounds are specified at window | |
| 2107 // creation time. | |
| 2108 ClientAreaSizeChanged(); | |
| 2109 | |
| 2110 delegate_->OnNativeWidgetCreated(); | 1892 delegate_->OnNativeWidgetCreated(); |
| 2111 } | 1893 } |
| 2112 | 1894 |
| 2113 void NativeWidgetWin::HandleDestroy() { | 1895 void NativeWidgetWin::HandleDestroy() { |
| 2114 delegate_->OnNativeWidgetDestroying(); | 1896 delegate_->OnNativeWidgetDestroying(); |
| 2115 if (drop_target_.get()) { | 1897 if (drop_target_.get()) { |
| 2116 RevokeDragDrop(hwnd()); | 1898 RevokeDragDrop(hwnd()); |
| 2117 drop_target_ = NULL; | 1899 drop_target_ = NULL; |
| 2118 } | 1900 } |
| 2119 } | 1901 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2141 } | 1923 } |
| 2142 | 1924 |
| 2143 void NativeWidgetWin::HandleMove() { | 1925 void NativeWidgetWin::HandleMove() { |
| 2144 delegate_->OnNativeWidgetMove(); | 1926 delegate_->OnNativeWidgetMove(); |
| 2145 } | 1927 } |
| 2146 | 1928 |
| 2147 void NativeWidgetWin::HandleWorkAreaChanged() { | 1929 void NativeWidgetWin::HandleWorkAreaChanged() { |
| 2148 GetWidget()->widget_delegate()->OnWorkAreaChanged(); | 1930 GetWidget()->widget_delegate()->OnWorkAreaChanged(); |
| 2149 } | 1931 } |
| 2150 | 1932 |
| 1933 void NativeWidgetWin::HandleVisibilityChanged(bool visible) { |
| 1934 delegate_->OnNativeWidgetVisibilityChanged(visible); |
| 1935 } |
| 1936 |
| 1937 void NativeWidgetWin::HandleClientSizeChanged(const gfx::Size& new_size) { |
| 1938 delegate_->OnNativeWidgetSizeChanged(new_size); |
| 1939 if (use_layered_buffer_) { |
| 1940 layered_window_contents_.reset( |
| 1941 new gfx::Canvas(new_size, ui::SCALE_FACTOR_100P, false)); |
| 1942 } |
| 1943 } |
| 1944 |
| 2151 void NativeWidgetWin::HandleNativeFocus(HWND last_focused_window) { | 1945 void NativeWidgetWin::HandleNativeFocus(HWND last_focused_window) { |
| 2152 delegate_->OnNativeFocus(last_focused_window); | 1946 delegate_->OnNativeFocus(last_focused_window); |
| 2153 } | 1947 } |
| 2154 | 1948 |
| 2155 void NativeWidgetWin::HandleNativeBlur(HWND focused_window) { | 1949 void NativeWidgetWin::HandleNativeBlur(HWND focused_window) { |
| 2156 delegate_->OnNativeBlur(focused_window); | 1950 delegate_->OnNativeBlur(focused_window); |
| 2157 } | 1951 } |
| 2158 | 1952 |
| 1953 bool NativeWidgetWin::HandleMouseEvent(const ui::MouseEvent& event) { |
| 1954 return delegate_->OnMouseEvent(event); |
| 1955 } |
| 1956 |
| 1957 bool NativeWidgetWin::HandleKeyEvent(const ui::KeyEvent& event) { |
| 1958 return delegate_->OnKeyEvent(event); |
| 1959 } |
| 1960 |
| 2159 void NativeWidgetWin::HandleScreenReaderDetected() { | 1961 void NativeWidgetWin::HandleScreenReaderDetected() { |
| 2160 // TODO(beng): just consolidate this with OnScreenReaderDetected. | 1962 // TODO(beng): just consolidate this with OnScreenReaderDetected. |
| 2161 OnScreenReaderDetected(); | 1963 OnScreenReaderDetected(); |
| 2162 } | 1964 } |
| 2163 | 1965 |
| 2164 bool NativeWidgetWin::HandleTooltipNotify(int w_param, | 1966 bool NativeWidgetWin::HandleTooltipNotify(int w_param, |
| 2165 NMHDR* l_param, | 1967 NMHDR* l_param, |
| 2166 LRESULT* l_result) { | 1968 LRESULT* l_result) { |
| 2167 // We can be sent this message before the tooltip manager is created, if a | 1969 // We can be sent this message before the tooltip manager is created, if a |
| 2168 // subclass overrides OnCreate and creates some kind of Windows control there | 1970 // subclass overrides OnCreate and creates some kind of Windows control there |
| 2169 // that sends WM_NOTIFY messages. | 1971 // that sends WM_NOTIFY messages. |
| 2170 if (tooltip_manager_.get()) { | 1972 if (tooltip_manager_.get()) { |
| 2171 bool handled; | 1973 bool handled; |
| 2172 *l_result = tooltip_manager_->OnNotify(w_param, l_param, &handled); | 1974 *l_result = tooltip_manager_->OnNotify(w_param, l_param, &handled); |
| 2173 return handled; | 1975 return handled; |
| 2174 } | 1976 } |
| 2175 return false; | 1977 return false; |
| 2176 } | 1978 } |
| 2177 | 1979 |
| 1980 void NativeWidgetWin::HandleTooltipMouseMove(UINT message, |
| 1981 WPARAM w_param, |
| 1982 LPARAM l_param) { |
| 1983 if (tooltip_manager_.get()) |
| 1984 tooltip_manager_->OnMouse(message, w_param, l_param); |
| 1985 } |
| 1986 |
| 2178 NativeWidgetWin* NativeWidgetWin::AsNativeWidgetWin() { | 1987 NativeWidgetWin* NativeWidgetWin::AsNativeWidgetWin() { |
| 2179 return this; | 1988 return this; |
| 2180 } | 1989 } |
| 2181 | 1990 |
| 2182 //////////////////////////////////////////////////////////////////////////////// | 1991 //////////////////////////////////////////////////////////////////////////////// |
| 2183 // NativeWidgetWin, private: | 1992 // NativeWidgetWin, private: |
| 2184 | 1993 |
| 2185 // static | 1994 // static |
| 2186 void NativeWidgetWin::PostProcessActivateMessage(NativeWidgetWin* widget, | 1995 void NativeWidgetWin::PostProcessActivateMessage(NativeWidgetWin* widget, |
| 2187 int activation_state) { | 1996 int activation_state) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2337 POINT position = {wr.left, wr.top}; | 2146 POINT position = {wr.left, wr.top}; |
| 2338 HDC dib_dc = skia::BeginPlatformPaint(layered_window_contents_->sk_canvas()); | 2147 HDC dib_dc = skia::BeginPlatformPaint(layered_window_contents_->sk_canvas()); |
| 2339 POINT zero = {0, 0}; | 2148 POINT zero = {0, 0}; |
| 2340 BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; | 2149 BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; |
| 2341 UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero, | 2150 UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero, |
| 2342 RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); | 2151 RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); |
| 2343 invalid_rect_.SetRect(0, 0, 0, 0); | 2152 invalid_rect_.SetRect(0, 0, 0, 0); |
| 2344 skia::EndPlatformPaint(layered_window_contents_->sk_canvas()); | 2153 skia::EndPlatformPaint(layered_window_contents_->sk_canvas()); |
| 2345 } | 2154 } |
| 2346 | 2155 |
| 2347 void NativeWidgetWin::LockUpdates(bool force) { | |
| 2348 // We skip locked updates when Aero is on for two reasons: | |
| 2349 // 1. Because it isn't necessary | |
| 2350 // 2. Because toggling the WS_VISIBLE flag may occur while the GPU process is | |
| 2351 // attempting to present a child window's backbuffer onscreen. When these | |
| 2352 // two actions race with one another, the child window will either flicker | |
| 2353 // or will simply stop updating entirely. | |
| 2354 if ((force || !IsAeroGlassEnabled()) && ++lock_updates_count_ == 1) | |
| 2355 SetWindowLong(GWL_STYLE, GetWindowLong(GWL_STYLE) & ~WS_VISIBLE); | |
| 2356 } | |
| 2357 | |
| 2358 void NativeWidgetWin::UnlockUpdates(bool force) { | |
| 2359 if ((force || !IsAeroGlassEnabled()) && --lock_updates_count_ <= 0) { | |
| 2360 SetWindowLong(GWL_STYLE, GetWindowLong(GWL_STYLE) | WS_VISIBLE); | |
| 2361 lock_updates_count_ = 0; | |
| 2362 } | |
| 2363 } | |
| 2364 | |
| 2365 bool NativeWidgetWin::WidgetSizeIsClientSize() const { | 2156 bool NativeWidgetWin::WidgetSizeIsClientSize() const { |
| 2366 const Widget* widget = GetWidget()->GetTopLevelWidget(); | 2157 const Widget* widget = GetWidget()->GetTopLevelWidget(); |
| 2367 return IsZoomed() || (widget && widget->ShouldUseNativeFrame()); | 2158 return IsZoomed() || (widget && widget->ShouldUseNativeFrame()); |
| 2368 } | 2159 } |
| 2369 | 2160 |
| 2370 void NativeWidgetWin::ClientAreaSizeChanged() { | |
| 2371 RECT r = {0, 0, 0, 0}; | |
| 2372 if (WidgetSizeIsClientSize()) { | |
| 2373 // TODO(beng): investigate whether this could be done | |
| 2374 // from other branch of if-else. | |
| 2375 if (!IsMinimized()) | |
| 2376 GetClientRect(&r); | |
| 2377 } else | |
| 2378 GetWindowRect(&r); | |
| 2379 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), | |
| 2380 std::max(0, static_cast<int>(r.bottom - r.top))); | |
| 2381 delegate_->OnNativeWidgetSizeChanged(s); | |
| 2382 if (use_layered_buffer_) | |
| 2383 layered_window_contents_.reset( | |
| 2384 new gfx::Canvas(s, ui::SCALE_FACTOR_100P, false)); | |
| 2385 } | |
| 2386 | |
| 2387 void NativeWidgetWin::UpdateDWMFrame() { | |
| 2388 MARGINS m = {10, 10, 10, 10}; | |
| 2389 DwmExtendFrameIntoClientArea(GetNativeView(), &m); | |
| 2390 } | |
| 2391 | |
| 2392 LRESULT NativeWidgetWin::DefWindowProcWithRedrawLock(UINT message, | |
| 2393 WPARAM w_param, | |
| 2394 LPARAM l_param) { | |
| 2395 ScopedRedrawLock lock(this); | |
| 2396 // The Widget and HWND can be destroyed in the call to DefWindowProc, so use | |
| 2397 // the |destroyed_| flag to avoid unlocking (and crashing) after destruction. | |
| 2398 bool destroyed = false; | |
| 2399 destroyed_ = &destroyed; | |
| 2400 LRESULT result = DefWindowProc(GetNativeView(), message, w_param, l_param); | |
| 2401 if (destroyed) | |
| 2402 lock.CancelUnlockOperation(); | |
| 2403 else | |
| 2404 destroyed_ = NULL; | |
| 2405 return result; | |
| 2406 } | |
| 2407 | |
| 2408 void NativeWidgetWin::RestoreEnabledIfNecessary() { | 2161 void NativeWidgetWin::RestoreEnabledIfNecessary() { |
| 2409 if (delegate_->IsModal() && !restored_enabled_) { | 2162 if (delegate_->IsModal() && !restored_enabled_) { |
| 2410 restored_enabled_ = true; | 2163 restored_enabled_ = true; |
| 2411 // If we were run modally, we need to undo the disabled-ness we inflicted on | 2164 // If we were run modally, we need to undo the disabled-ness we inflicted on |
| 2412 // the owner's parent hierarchy. | 2165 // the owner's parent hierarchy. |
| 2413 HWND start = ::GetWindow(GetNativeView(), GW_OWNER); | 2166 HWND start = ::GetWindow(GetNativeView(), GW_OWNER); |
| 2414 while (start) { | 2167 while (start) { |
| 2415 ::EnableWindow(start, TRUE); | 2168 ::EnableWindow(start, TRUE); |
| 2416 start = ::GetParent(start); | 2169 start = ::GetParent(start); |
| 2417 } | 2170 } |
| 2418 } | 2171 } |
| 2419 } | 2172 } |
| 2420 | 2173 |
| 2421 void NativeWidgetWin::NotifyOwnedWindowsParentClosing() { | 2174 void NativeWidgetWin::NotifyOwnedWindowsParentClosing() { |
| 2422 FindOwnedWindowsData data; | 2175 FindOwnedWindowsData data; |
| 2423 data.window = hwnd(); | 2176 data.window = hwnd(); |
| 2424 EnumThreadWindows(GetCurrentThreadId(), FindOwnedWindowsCallback, | 2177 EnumThreadWindows(GetCurrentThreadId(), FindOwnedWindowsCallback, |
| 2425 reinterpret_cast<LPARAM>(&data)); | 2178 reinterpret_cast<LPARAM>(&data)); |
| 2426 for (size_t i = 0; i < data.owned_widgets.size(); ++i) | 2179 for (size_t i = 0; i < data.owned_widgets.size(); ++i) |
| 2427 data.owned_widgets[i]->OnOwnerClosing(); | 2180 data.owned_widgets[i]->OnOwnerClosing(); |
| 2428 } | 2181 } |
| 2429 | 2182 |
| 2430 void NativeWidgetWin::DispatchKeyEventPostIME(const ui::KeyEvent& key) { | |
| 2431 SetMsgHandled(delegate_->OnKeyEvent(key)); | |
| 2432 } | |
| 2433 | |
| 2434 //////////////////////////////////////////////////////////////////////////////// | 2183 //////////////////////////////////////////////////////////////////////////////// |
| 2435 // Widget, public: | 2184 // Widget, public: |
| 2436 | 2185 |
| 2437 // static | 2186 // static |
| 2438 void Widget::NotifyLocaleChanged() { | 2187 void Widget::NotifyLocaleChanged() { |
| 2439 NOTIMPLEMENTED(); | 2188 NOTIMPLEMENTED(); |
| 2440 } | 2189 } |
| 2441 | 2190 |
| 2442 namespace { | 2191 namespace { |
| 2443 BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { | 2192 BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2594 // static | 2343 // static |
| 2595 bool NativeWidgetPrivate::IsTouchDown() { | 2344 bool NativeWidgetPrivate::IsTouchDown() { |
| 2596 // This currently isn't necessary because we're not generating touch events on | 2345 // This currently isn't necessary because we're not generating touch events on |
| 2597 // windows. When we do, this will need to be updated. | 2346 // windows. When we do, this will need to be updated. |
| 2598 return false; | 2347 return false; |
| 2599 } | 2348 } |
| 2600 | 2349 |
| 2601 } // namespace internal | 2350 } // namespace internal |
| 2602 | 2351 |
| 2603 } // namespace views | 2352 } // namespace views |
| OLD | NEW |