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

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

Issue 10827145: Convert Aura to use ui::Event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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_aura.h ('k') | ui/views/widget/native_widget_aura_unittest.cc » ('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_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"
11 #include "ui/aura/client/activation_client.h" 11 #include "ui/aura/client/activation_client.h"
12 #include "ui/aura/client/aura_constants.h" 12 #include "ui/aura/client/aura_constants.h"
13 #include "ui/aura/client/drag_drop_client.h" 13 #include "ui/aura/client/drag_drop_client.h"
14 #include "ui/aura/client/screen_position_client.h" 14 #include "ui/aura/client/screen_position_client.h"
15 #include "ui/aura/client/stacking_client.h" 15 #include "ui/aura/client/stacking_client.h"
16 #include "ui/aura/client/window_move_client.h" 16 #include "ui/aura/client/window_move_client.h"
17 #include "ui/aura/client/window_types.h" 17 #include "ui/aura/client/window_types.h"
18 #include "ui/aura/env.h" 18 #include "ui/aura/env.h"
19 #include "ui/aura/event.h"
20 #include "ui/aura/focus_manager.h" 19 #include "ui/aura/focus_manager.h"
21 #include "ui/aura/root_window.h" 20 #include "ui/aura/root_window.h"
22 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
23 #include "ui/aura/window_observer.h" 22 #include "ui/aura/window_observer.h"
23 #include "ui/base/event.h"
24 #include "ui/base/dragdrop/os_exchange_data.h" 24 #include "ui/base/dragdrop/os_exchange_data.h"
25 #include "ui/base/ui_base_types.h" 25 #include "ui/base/ui_base_types.h"
26 #include "ui/compositor/layer.h" 26 #include "ui/compositor/layer.h"
27 #include "ui/gfx/canvas.h" 27 #include "ui/gfx/canvas.h"
28 #include "ui/gfx/font.h" 28 #include "ui/gfx/font.h"
29 #include "ui/gfx/screen.h" 29 #include "ui/gfx/screen.h"
30 #include "ui/views/drag_utils.h" 30 #include "ui/views/drag_utils.h"
31 #include "ui/views/ime/input_method_bridge.h" 31 #include "ui/views/ime/input_method_bridge.h"
32 #include "ui/views/views_delegate.h" 32 #include "ui/views/views_delegate.h"
33 #include "ui/views/widget/drop_helper.h" 33 #include "ui/views/widget/drop_helper.h"
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, 380 parent_bounds.x() + (parent_bounds.width() - size.width()) / 2,
381 parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, 381 parent_bounds.y() + (parent_bounds.height() - size.height()) / 2,
382 size.width(), 382 size.width(),
383 size.height()); 383 size.height());
384 // Don't size the window bigger than the parent, otherwise the user may not be 384 // Don't size the window bigger than the parent, otherwise the user may not be
385 // able to close or move it. 385 // able to close or move it.
386 window_bounds = window_bounds.AdjustToFit(parent_bounds); 386 window_bounds = window_bounds.AdjustToFit(parent_bounds);
387 387
388 // Convert the bounds back relative to the parent. 388 // Convert the bounds back relative to the parent.
389 gfx::Point origin = window_bounds.origin(); 389 gfx::Point origin = window_bounds.origin();
390 aura::Window::ConvertPointToWindow(window_->GetRootWindow(), 390 aura::Window::ConvertPointToTarget(window_->GetRootWindow(),
391 window_->parent(), &origin); 391 window_->parent(), &origin);
392 window_bounds.set_origin(origin); 392 window_bounds.set_origin(origin);
393 window_->SetBounds(window_bounds); 393 window_->SetBounds(window_bounds);
394 } 394 }
395 395
396 void NativeWidgetAura::GetWindowPlacement( 396 void NativeWidgetAura::GetWindowPlacement(
397 gfx::Rect* bounds, 397 gfx::Rect* bounds,
398 ui::WindowShowState* show_state) const { 398 ui::WindowShowState* show_state) const {
399 // The interface specifies returning restored bounds, not current bounds. 399 // The interface specifies returning restored bounds, not current bounds.
400 *bounds = GetRestoredBounds(); 400 *bounds = GetRestoredBounds();
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the case 727 // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the case
728 // in tests). 728 // in tests).
729 if (!destroying_) 729 if (!destroying_)
730 GetWidget()->GetInputMethod()->OnBlur(); 730 GetWidget()->GetInputMethod()->OnBlur();
731 else 731 else
732 DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); 732 DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
733 733
734 delegate_->OnNativeBlur(window_->GetFocusManager()->GetFocusedWindow()); 734 delegate_->OnNativeBlur(window_->GetFocusManager()->GetFocusedWindow());
735 } 735 }
736 736
737 bool NativeWidgetAura::OnKeyEvent(aura::KeyEvent* event) { 737 bool NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) {
738 if (event->is_char()) { 738 if (event->is_char()) {
739 // If a ui::InputMethod object is attached to the root window, character 739 // If a ui::InputMethod object is attached to the root window, character
740 // events are handled inside the object and are not passed to this function. 740 // events are handled inside the object and are not passed to this function.
741 // If such object is not attached, character events might be sent (e.g. on 741 // If such object is not attached, character events might be sent (e.g. on
742 // Windows). In this case, we just skip these. 742 // Windows). In this case, we just skip these.
743 return false; 743 return false;
744 } 744 }
745 // Renderer may send a key event back to us if the key event wasn't handled, 745 // Renderer may send a key event back to us if the key event wasn't handled,
746 // and the window may be invisible by that time. 746 // and the window may be invisible by that time.
747 if (!window_->IsVisible()) 747 if (!window_->IsVisible())
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 Layers::const_iterator root_layer_iter( 784 Layers::const_iterator root_layer_iter(
785 std::find(window_->layer()->children().begin(), 785 std::find(window_->layer()->children().begin(),
786 window_->layer()->children().end(), layer)); 786 window_->layer()->children().end(), layer));
787 if (root_layer_iter > child_layer_iter) 787 if (root_layer_iter > child_layer_iter)
788 return false; 788 return false;
789 } 789 }
790 } 790 }
791 return true; 791 return true;
792 } 792 }
793 793
794 bool NativeWidgetAura::OnMouseEvent(aura::MouseEvent* event) { 794 bool NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) {
795 DCHECK(window_->IsVisible()); 795 DCHECK(window_->IsVisible());
796 if (event->type() == ui::ET_MOUSEWHEEL) { 796 if (event->type() == ui::ET_MOUSEWHEEL) {
797 MouseWheelEvent wheel_event(event); 797 MouseWheelEvent wheel_event(event);
798 return delegate_->OnMouseEvent(wheel_event); 798 return delegate_->OnMouseEvent(wheel_event);
799 } 799 }
800 if (event->type() == ui::ET_SCROLL) { 800 if (event->type() == ui::ET_SCROLL) {
801 ScrollEvent scroll_event(static_cast<aura::ScrollEvent*>(event)); 801 ScrollEvent scroll_event(static_cast<ui::ScrollEvent*>(event));
802 if (delegate_->OnMouseEvent(scroll_event)) 802 if (delegate_->OnMouseEvent(scroll_event))
803 return true; 803 return true;
804 804
805 // Convert unprocessed scroll events into wheel events. 805 // Convert unprocessed scroll events into wheel events.
806 MouseWheelEvent wheel_event(scroll_event); 806 MouseWheelEvent wheel_event(scroll_event);
807 return delegate_->OnMouseEvent(wheel_event); 807 return delegate_->OnMouseEvent(wheel_event);
808 } 808 }
809 MouseEvent mouse_event(event); 809 MouseEvent mouse_event(event);
810 if (tooltip_manager_.get()) 810 if (tooltip_manager_.get())
811 tooltip_manager_->UpdateTooltip(); 811 tooltip_manager_->UpdateTooltip();
812 return delegate_->OnMouseEvent(mouse_event); 812 return delegate_->OnMouseEvent(mouse_event);
813 } 813 }
814 814
815 ui::TouchStatus NativeWidgetAura::OnTouchEvent(aura::TouchEvent* event) { 815 ui::TouchStatus NativeWidgetAura::OnTouchEvent(ui::TouchEventImpl* event) {
816 DCHECK(window_->IsVisible()); 816 DCHECK(window_->IsVisible());
817 TouchEvent touch_event(event); 817 TouchEvent touch_event(event);
818 return delegate_->OnTouchEvent(touch_event); 818 return delegate_->OnTouchEvent(touch_event);
819 } 819 }
820 820
821 ui::GestureStatus NativeWidgetAura::OnGestureEvent(aura::GestureEvent* event) { 821 ui::GestureStatus NativeWidgetAura::OnGestureEvent(
822 ui::GestureEventImpl* event) {
822 DCHECK(window_->IsVisible()); 823 DCHECK(window_->IsVisible());
823 GestureEvent gesture_event(event); 824 GestureEvent gesture_event(event);
824 return delegate_->OnGestureEvent(gesture_event); 825 return delegate_->OnGestureEvent(gesture_event);
825 } 826 }
826 827
827 bool NativeWidgetAura::CanFocus() { 828 bool NativeWidgetAura::CanFocus() {
828 return can_activate_; 829 return can_activate_;
829 } 830 }
830 831
831 void NativeWidgetAura::OnCaptureLost() { 832 void NativeWidgetAura::OnCaptureLost() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 } 865 }
865 866
866 void NativeWidgetAura::GetHitTestMask(gfx::Path* mask) const { 867 void NativeWidgetAura::GetHitTestMask(gfx::Path* mask) const {
867 DCHECK(mask); 868 DCHECK(mask);
868 delegate_->GetHitTestMask(mask); 869 delegate_->GetHitTestMask(mask);
869 } 870 }
870 871
871 //////////////////////////////////////////////////////////////////////////////// 872 ////////////////////////////////////////////////////////////////////////////////
872 // NativeWidgetAura, aura::ActivationDelegate implementation: 873 // NativeWidgetAura, aura::ActivationDelegate implementation:
873 874
874 bool NativeWidgetAura::ShouldActivate(const aura::Event* event) { 875 bool NativeWidgetAura::ShouldActivate(const ui::Event* event) {
875 return can_activate_ && delegate_->CanActivate(); 876 return can_activate_ && delegate_->CanActivate();
876 } 877 }
877 878
878 void NativeWidgetAura::OnActivated() { 879 void NativeWidgetAura::OnActivated() {
879 if (GetWidget()->HasFocusManager()) 880 if (GetWidget()->HasFocusManager())
880 GetWidget()->GetFocusManager()->RestoreFocusedView(); 881 GetWidget()->GetFocusManager()->RestoreFocusedView();
881 delegate_->OnNativeWidgetActivationChanged(true); 882 delegate_->OnNativeWidgetActivationChanged(true);
882 if (IsVisible() && GetWidget()->non_client_view()) 883 if (IsVisible() && GetWidget()->non_client_view())
883 GetWidget()->non_client_view()->SchedulePaint(); 884 GetWidget()->non_client_view()->SchedulePaint();
884 } 885 }
885 886
886 void NativeWidgetAura::OnLostActive() { 887 void NativeWidgetAura::OnLostActive() {
887 if (GetWidget()->HasFocusManager()) 888 if (GetWidget()->HasFocusManager())
888 GetWidget()->GetFocusManager()->StoreFocusedView(); 889 GetWidget()->GetFocusManager()->StoreFocusedView();
889 delegate_->OnNativeWidgetActivationChanged(false); 890 delegate_->OnNativeWidgetActivationChanged(false);
890 if (IsVisible() && GetWidget()->non_client_view()) 891 if (IsVisible() && GetWidget()->non_client_view())
891 GetWidget()->non_client_view()->SchedulePaint(); 892 GetWidget()->non_client_view()->SchedulePaint();
892 } 893 }
893 894
894 //////////////////////////////////////////////////////////////////////////////// 895 ////////////////////////////////////////////////////////////////////////////////
895 // NativeWidgetAura, aura::WindowDragDropDelegate implementation: 896 // NativeWidgetAura, aura::WindowDragDropDelegate implementation:
896 897
897 void NativeWidgetAura::OnDragEntered(const aura::DropTargetEvent& event) { 898 void NativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) {
898 DCHECK(drop_helper_.get() != NULL); 899 DCHECK(drop_helper_.get() != NULL);
899 last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 900 last_drop_operation_ = drop_helper_->OnDragOver(event.data(),
900 event.location(), event.source_operations()); 901 event.location(), event.source_operations());
901 } 902 }
902 903
903 int NativeWidgetAura::OnDragUpdated(const aura::DropTargetEvent& event) { 904 int NativeWidgetAura::OnDragUpdated(const ui::DropTargetEvent& event) {
904 DCHECK(drop_helper_.get() != NULL); 905 DCHECK(drop_helper_.get() != NULL);
905 last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 906 last_drop_operation_ = drop_helper_->OnDragOver(event.data(),
906 event.location(), event.source_operations()); 907 event.location(), event.source_operations());
907 return last_drop_operation_; 908 return last_drop_operation_;
908 } 909 }
909 910
910 void NativeWidgetAura::OnDragExited() { 911 void NativeWidgetAura::OnDragExited() {
911 DCHECK(drop_helper_.get() != NULL); 912 DCHECK(drop_helper_.get() != NULL);
912 drop_helper_->OnDragExit(); 913 drop_helper_->OnDragExit();
913 } 914 }
914 915
915 int NativeWidgetAura::OnPerformDrop(const aura::DropTargetEvent& event) { 916 int NativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) {
916 DCHECK(drop_helper_.get() != NULL); 917 DCHECK(drop_helper_.get() != NULL);
917 return drop_helper_->OnDrop(event.data(), event.location(), 918 return drop_helper_->OnDrop(event.data(), event.location(),
918 last_drop_operation_); 919 last_drop_operation_);
919 } 920 }
920 921
921 //////////////////////////////////////////////////////////////////////////////// 922 ////////////////////////////////////////////////////////////////////////////////
922 // NativeWidgetAura, protected: 923 // NativeWidgetAura, protected:
923 924
924 NativeWidgetAura::~NativeWidgetAura() { 925 NativeWidgetAura::~NativeWidgetAura() {
925 destroying_ = true; 926 destroying_ = true;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 return aura::Env::GetInstance()->is_mouse_button_down(); 1049 return aura::Env::GetInstance()->is_mouse_button_down();
1049 } 1050 }
1050 1051
1051 // static 1052 // static
1052 bool NativeWidgetPrivate::IsTouchDown() { 1053 bool NativeWidgetPrivate::IsTouchDown() {
1053 return aura::Env::GetInstance()->is_touch_down(); 1054 return aura::Env::GetInstance()->is_touch_down();
1054 } 1055 }
1055 1056
1056 } // namespace internal 1057 } // namespace internal
1057 } // namespace views 1058 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_aura.h ('k') | ui/views/widget/native_widget_aura_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698