| 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_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "third_party/skia/include/core/SkRegion.h" | 9 #include "third_party/skia/include/core/SkRegion.h" |
| 10 #include "ui/aura/client/activation_change_observer.h" | 10 #include "ui/aura/client/activation_change_observer.h" |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the case | 736 // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the case |
| 737 // in tests). | 737 // in tests). |
| 738 if (!destroying_) | 738 if (!destroying_) |
| 739 GetWidget()->GetInputMethod()->OnBlur(); | 739 GetWidget()->GetInputMethod()->OnBlur(); |
| 740 else | 740 else |
| 741 DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); | 741 DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); |
| 742 | 742 |
| 743 delegate_->OnNativeBlur(window_->GetFocusManager()->GetFocusedWindow()); | 743 delegate_->OnNativeBlur(window_->GetFocusManager()->GetFocusedWindow()); |
| 744 } | 744 } |
| 745 | 745 |
| 746 bool NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { | |
| 747 if (event->is_char()) { | |
| 748 // If a ui::InputMethod object is attached to the root window, character | |
| 749 // events are handled inside the object and are not passed to this function. | |
| 750 // If such object is not attached, character events might be sent (e.g. on | |
| 751 // Windows). In this case, we just skip these. | |
| 752 return false; | |
| 753 } | |
| 754 // Renderer may send a key event back to us if the key event wasn't handled, | |
| 755 // and the window may be invisible by that time. | |
| 756 if (!window_->IsVisible()) | |
| 757 return false; | |
| 758 GetWidget()->GetInputMethod()->DispatchKeyEvent(*event); | |
| 759 return true; | |
| 760 } | |
| 761 | |
| 762 gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) { | 746 gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) { |
| 763 return cursor_; | 747 return cursor_; |
| 764 } | 748 } |
| 765 | 749 |
| 766 int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { | 750 int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { |
| 767 return delegate_->GetNonClientComponent(point); | 751 return delegate_->GetNonClientComponent(point); |
| 768 } | 752 } |
| 769 | 753 |
| 770 bool NativeWidgetAura::ShouldDescendIntoChildForEventHandling( | 754 bool NativeWidgetAura::ShouldDescendIntoChildForEventHandling( |
| 771 aura::Window* child, | 755 aura::Window* child, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 795 Layers::const_iterator root_layer_iter( | 779 Layers::const_iterator root_layer_iter( |
| 796 std::find(window_->layer()->children().begin(), | 780 std::find(window_->layer()->children().begin(), |
| 797 window_->layer()->children().end(), layer)); | 781 window_->layer()->children().end(), layer)); |
| 798 if (root_layer_iter > child_layer_iter) | 782 if (root_layer_iter > child_layer_iter) |
| 799 return false; | 783 return false; |
| 800 } | 784 } |
| 801 } | 785 } |
| 802 return true; | 786 return true; |
| 803 } | 787 } |
| 804 | 788 |
| 805 bool NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { | |
| 806 DCHECK(window_->IsVisible()); | |
| 807 if (event->type() == ui::ET_MOUSEWHEEL) | |
| 808 return delegate_->OnMouseEvent(*event); | |
| 809 | |
| 810 if (event->type() == ui::ET_SCROLL) { | |
| 811 if (delegate_->OnMouseEvent(*event)) | |
| 812 return true; | |
| 813 | |
| 814 // Convert unprocessed scroll events into wheel events. | |
| 815 ui::MouseWheelEvent mwe(*static_cast<ui::ScrollEvent*>(event)); | |
| 816 return delegate_->OnMouseEvent(mwe); | |
| 817 } | |
| 818 if (tooltip_manager_.get()) | |
| 819 tooltip_manager_->UpdateTooltip(); | |
| 820 return delegate_->OnMouseEvent(*event); | |
| 821 } | |
| 822 | |
| 823 ui::TouchStatus NativeWidgetAura::OnTouchEvent(ui::TouchEvent* event) { | |
| 824 DCHECK(window_->IsVisible()); | |
| 825 return delegate_->OnTouchEvent(*event); | |
| 826 } | |
| 827 | |
| 828 ui::EventResult NativeWidgetAura::OnGestureEvent( | |
| 829 ui::GestureEvent* event) { | |
| 830 DCHECK(window_->IsVisible()); | |
| 831 return delegate_->OnGestureEvent(*event); | |
| 832 } | |
| 833 | |
| 834 bool NativeWidgetAura::CanFocus() { | 789 bool NativeWidgetAura::CanFocus() { |
| 835 return can_activate_; | 790 return can_activate_; |
| 836 } | 791 } |
| 837 | 792 |
| 838 void NativeWidgetAura::OnCaptureLost() { | 793 void NativeWidgetAura::OnCaptureLost() { |
| 839 delegate_->OnMouseCaptureLost(); | 794 delegate_->OnMouseCaptureLost(); |
| 840 } | 795 } |
| 841 | 796 |
| 842 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { | 797 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { |
| 843 delegate_->OnNativeWidgetPaint(canvas); | 798 delegate_->OnNativeWidgetPaint(canvas); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 869 bool NativeWidgetAura::HasHitTestMask() const { | 824 bool NativeWidgetAura::HasHitTestMask() const { |
| 870 return delegate_->HasHitTestMask(); | 825 return delegate_->HasHitTestMask(); |
| 871 } | 826 } |
| 872 | 827 |
| 873 void NativeWidgetAura::GetHitTestMask(gfx::Path* mask) const { | 828 void NativeWidgetAura::GetHitTestMask(gfx::Path* mask) const { |
| 874 DCHECK(mask); | 829 DCHECK(mask); |
| 875 delegate_->GetHitTestMask(mask); | 830 delegate_->GetHitTestMask(mask); |
| 876 } | 831 } |
| 877 | 832 |
| 878 //////////////////////////////////////////////////////////////////////////////// | 833 //////////////////////////////////////////////////////////////////////////////// |
| 834 // NativeWidgetAura, ui::EventHandler implementation: |
| 835 |
| 836 ui::EventResult NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { |
| 837 if (event->is_char()) { |
| 838 // If a ui::InputMethod object is attached to the root window, character |
| 839 // events are handled inside the object and are not passed to this function. |
| 840 // If such object is not attached, character events might be sent (e.g. on |
| 841 // Windows). In this case, we just skip these. |
| 842 return ui::ER_UNHANDLED; |
| 843 } |
| 844 // Renderer may send a key event back to us if the key event wasn't handled, |
| 845 // and the window may be invisible by that time. |
| 846 if (!window_->IsVisible()) |
| 847 return ui::ER_UNHANDLED; |
| 848 GetWidget()->GetInputMethod()->DispatchKeyEvent(*event); |
| 849 return ui::ER_HANDLED; |
| 850 } |
| 851 |
| 852 ui::EventResult NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { |
| 853 DCHECK(window_->IsVisible()); |
| 854 if (event->type() == ui::ET_MOUSEWHEEL) |
| 855 return delegate_->OnMouseEvent(*event) ? ui::ER_HANDLED : ui::ER_UNHANDLED; |
| 856 |
| 857 if (event->type() == ui::ET_SCROLL) { |
| 858 if (delegate_->OnMouseEvent(*event)) |
| 859 return ui::ER_HANDLED; |
| 860 |
| 861 // Convert unprocessed scroll events into wheel events. |
| 862 ui::MouseWheelEvent mwe(*static_cast<ui::ScrollEvent*>(event)); |
| 863 return delegate_->OnMouseEvent(mwe) ? ui::ER_HANDLED : ui::ER_UNHANDLED; |
| 864 } |
| 865 if (tooltip_manager_.get()) |
| 866 tooltip_manager_->UpdateTooltip(); |
| 867 return delegate_->OnMouseEvent(*event) ? ui::ER_HANDLED : ui::ER_UNHANDLED; |
| 868 } |
| 869 |
| 870 ui::TouchStatus NativeWidgetAura::OnTouchEvent(ui::TouchEvent* event) { |
| 871 DCHECK(window_->IsVisible()); |
| 872 return delegate_->OnTouchEvent(*event); |
| 873 } |
| 874 |
| 875 ui::EventResult NativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) { |
| 876 DCHECK(window_->IsVisible()); |
| 877 return delegate_->OnGestureEvent(*event); |
| 878 } |
| 879 |
| 880 //////////////////////////////////////////////////////////////////////////////// |
| 879 // NativeWidgetAura, aura::ActivationDelegate implementation: | 881 // NativeWidgetAura, aura::ActivationDelegate implementation: |
| 880 | 882 |
| 881 bool NativeWidgetAura::ShouldActivate(const ui::Event* event) { | 883 bool NativeWidgetAura::ShouldActivate(const ui::Event* event) { |
| 882 return can_activate_ && delegate_->CanActivate(); | 884 return can_activate_ && delegate_->CanActivate(); |
| 883 } | 885 } |
| 884 | 886 |
| 885 void NativeWidgetAura::OnActivated() { | 887 void NativeWidgetAura::OnActivated() { |
| 886 if (GetWidget()->HasFocusManager()) | 888 if (GetWidget()->HasFocusManager()) |
| 887 GetWidget()->GetFocusManager()->RestoreFocusedView(); | 889 GetWidget()->GetFocusManager()->RestoreFocusedView(); |
| 888 delegate_->OnNativeWidgetActivationChanged(true); | 890 delegate_->OnNativeWidgetActivationChanged(true); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 return aura::Env::GetInstance()->is_mouse_button_down(); | 1057 return aura::Env::GetInstance()->is_mouse_button_down(); |
| 1056 } | 1058 } |
| 1057 | 1059 |
| 1058 // static | 1060 // static |
| 1059 bool NativeWidgetPrivate::IsTouchDown() { | 1061 bool NativeWidgetPrivate::IsTouchDown() { |
| 1060 return aura::Env::GetInstance()->is_touch_down(); | 1062 return aura::Env::GetInstance()->is_touch_down(); |
| 1061 } | 1063 } |
| 1062 | 1064 |
| 1063 } // namespace internal | 1065 } // namespace internal |
| 1064 } // namespace views | 1066 } // namespace views |
| OLD | NEW |