| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <dwmapi.h> | 7 #include <dwmapi.h> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
| 11 #include "ui/base/dragdrop/drag_drop_types.h" |
| 12 #include "ui/base/dragdrop/drag_source.h" |
| 13 #include "ui/base/dragdrop/os_exchange_data.h" |
| 14 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
| 11 #include "ui/base/keycodes/keyboard_code_conversion_win.h" | 15 #include "ui/base/keycodes/keyboard_code_conversion_win.h" |
| 12 #include "ui/base/l10n/l10n_util_win.h" | 16 #include "ui/base/l10n/l10n_util_win.h" |
| 13 #include "ui/base/system_monitor/system_monitor.h" | 17 #include "ui/base/system_monitor/system_monitor.h" |
| 14 #include "ui/base/theme_provider.h" | 18 #include "ui/base/theme_provider.h" |
| 15 #include "ui/base/view_prop.h" | 19 #include "ui/base/view_prop.h" |
| 16 #include "ui/base/win/hwnd_util.h" | 20 #include "ui/base/win/hwnd_util.h" |
| 17 #include "ui/gfx/canvas_skia.h" | 21 #include "ui/gfx/canvas_skia.h" |
| 18 #include "ui/gfx/native_theme_win.h" | 22 #include "ui/gfx/native_theme_win.h" |
| 19 #include "ui/gfx/path.h" | 23 #include "ui/gfx/path.h" |
| 20 #include "views/accessibility/view_accessibility.h" | 24 #include "views/accessibility/view_accessibility.h" |
| 21 #include "views/controls/native_control_win.h" | 25 #include "views/controls/native_control_win.h" |
| 22 #include "views/focus/accelerator_handler.h" | 26 #include "views/focus/accelerator_handler.h" |
| 23 #include "views/focus/focus_util_win.h" | 27 #include "views/focus/focus_util_win.h" |
| 28 #include "views/focus/view_storage.h" |
| 24 #include "views/views_delegate.h" | 29 #include "views/views_delegate.h" |
| 25 #include "views/widget/aero_tooltip_manager.h" | 30 #include "views/widget/aero_tooltip_manager.h" |
| 26 #include "views/widget/child_window_message_processor.h" | 31 #include "views/widget/child_window_message_processor.h" |
| 27 #include "views/widget/default_theme_provider.h" | 32 #include "views/widget/default_theme_provider.h" |
| 28 #include "views/widget/drop_target_win.h" | 33 #include "views/widget/drop_target_win.h" |
| 29 #include "views/widget/root_view.h" | 34 #include "views/widget/root_view.h" |
| 30 #include "views/widget/widget_delegate.h" | 35 #include "views/widget/widget_delegate.h" |
| 31 #include "views/widget/widget_utils.h" | 36 #include "views/widget/widget_utils.h" |
| 32 #include "views/window/window_win.h" | 37 #include "views/window/window_win.h" |
| 33 | 38 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 use_layered_buffer_(true), | 81 use_layered_buffer_(true), |
| 77 layered_alpha_(255), | 82 layered_alpha_(255), |
| 78 delete_on_destroy_(true), | 83 delete_on_destroy_(true), |
| 79 can_update_layered_window_(true), | 84 can_update_layered_window_(true), |
| 80 last_mouse_event_was_move_(false), | 85 last_mouse_event_was_move_(false), |
| 81 is_mouse_down_(false), | 86 is_mouse_down_(false), |
| 82 is_window_(false), | 87 is_window_(false), |
| 83 restore_focus_when_enabled_(false), | 88 restore_focus_when_enabled_(false), |
| 84 delegate_(NULL), | 89 delegate_(NULL), |
| 85 accessibility_view_events_index_(-1), | 90 accessibility_view_events_index_(-1), |
| 86 accessibility_view_events_(kMaxAccessibilityViewEvents) { | 91 accessibility_view_events_(kMaxAccessibilityViewEvents), |
| 92 dragged_view_(NULL) { |
| 87 } | 93 } |
| 88 | 94 |
| 89 WidgetWin::~WidgetWin() { | 95 WidgetWin::~WidgetWin() { |
| 90 } | 96 } |
| 91 | 97 |
| 92 // static | 98 // static |
| 93 WidgetWin* WidgetWin::GetWidget(HWND hwnd) { | 99 WidgetWin* WidgetWin::GetWidget(HWND hwnd) { |
| 94 // TODO(jcivelli): http://crbug.com/44499 We need a way to test that hwnd is | 100 // TODO(jcivelli): http://crbug.com/44499 We need a way to test that hwnd is |
| 95 // associated with a WidgetWin (it might be a pure | 101 // associated with a WidgetWin (it might be a pure |
| 96 // WindowImpl). | 102 // WindowImpl). |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 return widget->GetFocusManager(); | 492 return widget->GetFocusManager(); |
| 487 } | 493 } |
| 488 return NULL; | 494 return NULL; |
| 489 } | 495 } |
| 490 | 496 |
| 491 void WidgetWin::ViewHierarchyChanged(bool is_add, View *parent, | 497 void WidgetWin::ViewHierarchyChanged(bool is_add, View *parent, |
| 492 View *child) { | 498 View *child) { |
| 493 if (drop_target_.get()) | 499 if (drop_target_.get()) |
| 494 drop_target_->ResetTargetViewIfEquals(child); | 500 drop_target_->ResetTargetViewIfEquals(child); |
| 495 | 501 |
| 496 if (!is_add) | 502 if (!is_add) { |
| 497 ClearAccessibilityViewEvent(child); | 503 ClearAccessibilityViewEvent(child); |
| 504 |
| 505 if (child == dragged_view_) |
| 506 dragged_view_ = NULL; |
| 507 |
| 508 FocusManager* focus_manager = GetFocusManager(); |
| 509 if (focus_manager) |
| 510 focus_manager->ViewRemoved(parent, child); |
| 511 ViewStorage::GetInstance()->ViewRemoved(parent, child); |
| 512 } |
| 498 } | 513 } |
| 499 | 514 |
| 500 | |
| 501 bool WidgetWin::ContainsNativeView(gfx::NativeView native_view) { | 515 bool WidgetWin::ContainsNativeView(gfx::NativeView native_view) { |
| 502 if (hwnd() == native_view) | 516 if (hwnd() == native_view) |
| 503 return true; | 517 return true; |
| 504 | 518 |
| 505 // Traverse the set of parents of the given view to determine if native_view | 519 // Traverse the set of parents of the given view to determine if native_view |
| 506 // is a descendant of this window. | 520 // is a descendant of this window. |
| 507 HWND parent_window = ::GetParent(native_view); | 521 HWND parent_window = ::GetParent(native_view); |
| 508 HWND previous_child = native_view; | 522 HWND previous_child = native_view; |
| 509 while (parent_window && parent_window != previous_child) { | 523 while (parent_window && parent_window != previous_child) { |
| 510 if (hwnd() == parent_window) | 524 if (hwnd() == parent_window) |
| 511 return true; | 525 return true; |
| 512 previous_child = parent_window; | 526 previous_child = parent_window; |
| 513 parent_window = ::GetParent(parent_window); | 527 parent_window = ::GetParent(parent_window); |
| 514 } | 528 } |
| 515 | 529 |
| 516 // A views::NativeViewHost may contain the given native view, without it being | 530 // A views::NativeViewHost may contain the given native view, without it being |
| 517 // an ancestor of hwnd(), so traverse the views::View hierarchy looking for | 531 // an ancestor of hwnd(), so traverse the views::View hierarchy looking for |
| 518 // such views. | 532 // such views. |
| 519 return GetRootView()->ContainsNativeView(native_view); | 533 return GetRootView()->ContainsNativeView(native_view); |
| 520 } | 534 } |
| 521 | 535 |
| 536 void WidgetWin::StartDragForViewFromMouseEvent( |
| 537 View* view, |
| 538 const ui::OSExchangeData& data, |
| 539 int operation) { |
| 540 // NOTE: view may be null. |
| 541 dragged_view_ = view; |
| 542 scoped_refptr<ui::DragSource> drag_source(new ui::DragSource); |
| 543 DWORD effects; |
| 544 DoDragDrop(ui::OSExchangeDataProviderWin::GetIDataObject(data), drag_source, |
| 545 ui::DragDropTypes::DragOperationToDropEffect(operation), &effects); |
| 546 // If the view is removed during the drag operation, drag_view_ is set to |
| 547 // NULL. |
| 548 if (view && dragged_view_ == view) { |
| 549 dragged_view_ = NULL; |
| 550 view->OnDragDone(); |
| 551 } |
| 552 } |
| 553 |
| 554 View* WidgetWin::GetDraggedView() { |
| 555 return dragged_view_; |
| 556 } |
| 557 |
| 522 //////////////////////////////////////////////////////////////////////////////// | 558 //////////////////////////////////////////////////////////////////////////////// |
| 523 // MessageLoop::Observer | 559 // MessageLoop::Observer |
| 524 | 560 |
| 525 void WidgetWin::WillProcessMessage(const MSG& msg) { | 561 void WidgetWin::WillProcessMessage(const MSG& msg) { |
| 526 } | 562 } |
| 527 | 563 |
| 528 void WidgetWin::DidProcessMessage(const MSG& msg) { | 564 void WidgetWin::DidProcessMessage(const MSG& msg) { |
| 529 if (root_view_->NeedsPainting(true)) | 565 if (root_view_->NeedsPainting(true)) |
| 530 PaintNow(root_view_->GetScheduledPaintRect()); | 566 PaintNow(root_view_->GetScheduledPaintRect()); |
| 531 } | 567 } |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) { | 1432 Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) { |
| 1397 return Widget::GetWidgetFromNativeView(native_window); | 1433 return Widget::GetWidgetFromNativeView(native_window); |
| 1398 } | 1434 } |
| 1399 | 1435 |
| 1400 // static | 1436 // static |
| 1401 void Widget::NotifyLocaleChanged() { | 1437 void Widget::NotifyLocaleChanged() { |
| 1402 NOTIMPLEMENTED(); | 1438 NOTIMPLEMENTED(); |
| 1403 } | 1439 } |
| 1404 | 1440 |
| 1405 } // namespace views | 1441 } // namespace views |
| OLD | NEW |