| 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
| 6 | 6 |
| 7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 } | 924 } |
| 925 | 925 |
| 926 void View::OnKeyEvent(ui::KeyEvent* event) { | 926 void View::OnKeyEvent(ui::KeyEvent* event) { |
| 927 bool consumed = (event->type() == ui::ET_KEY_PRESSED) ? OnKeyPressed(*event) : | 927 bool consumed = (event->type() == ui::ET_KEY_PRESSED) ? OnKeyPressed(*event) : |
| 928 OnKeyReleased(*event); | 928 OnKeyReleased(*event); |
| 929 if (consumed) | 929 if (consumed) |
| 930 event->StopPropagation(); | 930 event->StopPropagation(); |
| 931 } | 931 } |
| 932 | 932 |
| 933 void View::OnMouseEvent(ui::MouseEvent* event) { | 933 void View::OnMouseEvent(ui::MouseEvent* event) { |
| 934 switch (event->type()) { |
| 935 case ui::ET_MOUSE_PRESSED: |
| 936 if (ProcessMousePressed(*event)) |
| 937 event->SetHandled(); |
| 938 return; |
| 939 |
| 940 case ui::ET_MOUSE_MOVED: |
| 941 if ((event->flags() & (ui::EF_LEFT_MOUSE_BUTTON | |
| 942 ui::EF_RIGHT_MOUSE_BUTTON | |
| 943 ui::EF_MIDDLE_MOUSE_BUTTON)) == 0) { |
| 944 OnMouseMoved(*event); |
| 945 return; |
| 946 } |
| 947 // FALL-THROUGH |
| 948 case ui::ET_MOUSE_DRAGGED: |
| 949 if (ProcessMouseDragged(*event)) |
| 950 event->SetHandled(); |
| 951 return; |
| 952 |
| 953 case ui::ET_MOUSE_RELEASED: |
| 954 ProcessMouseReleased(*event); |
| 955 return; |
| 956 |
| 957 case ui::ET_MOUSEWHEEL: |
| 958 if (OnMouseWheel(*static_cast<ui::MouseWheelEvent*>(event))) |
| 959 event->SetHandled(); |
| 960 break; |
| 961 |
| 962 case ui::ET_MOUSE_ENTERED: |
| 963 OnMouseEntered(*event); |
| 964 break; |
| 965 |
| 966 case ui::ET_MOUSE_EXITED: |
| 967 OnMouseExited(*event); |
| 968 break; |
| 969 |
| 970 default: |
| 971 return; |
| 972 } |
| 934 } | 973 } |
| 935 | 974 |
| 936 void View::OnScrollEvent(ui::ScrollEvent* event) { | 975 void View::OnScrollEvent(ui::ScrollEvent* event) { |
| 937 } | 976 } |
| 938 | 977 |
| 939 void View::OnTouchEvent(ui::TouchEvent* event) { | 978 void View::OnTouchEvent(ui::TouchEvent* event) { |
| 940 } | 979 } |
| 941 | 980 |
| 942 void View::OnGestureEvent(ui::GestureEvent* event) { | 981 void View::OnGestureEvent(ui::GestureEvent* event) { |
| 943 } | 982 } |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 // Input ----------------------------------------------------------------------- | 1411 // Input ----------------------------------------------------------------------- |
| 1373 | 1412 |
| 1374 bool View::HasHitTestMask() const { | 1413 bool View::HasHitTestMask() const { |
| 1375 return false; | 1414 return false; |
| 1376 } | 1415 } |
| 1377 | 1416 |
| 1378 void View::GetHitTestMask(gfx::Path* mask) const { | 1417 void View::GetHitTestMask(gfx::Path* mask) const { |
| 1379 DCHECK(mask); | 1418 DCHECK(mask); |
| 1380 } | 1419 } |
| 1381 | 1420 |
| 1421 View::DragInfo* View::GetDragInfo() { |
| 1422 return parent_ ? parent_->GetDragInfo() : NULL; |
| 1423 } |
| 1424 |
| 1382 // Focus ----------------------------------------------------------------------- | 1425 // Focus ----------------------------------------------------------------------- |
| 1383 | 1426 |
| 1384 void View::OnFocus() { | 1427 void View::OnFocus() { |
| 1385 // TODO(beng): Investigate whether it's possible for us to move this to | 1428 // TODO(beng): Investigate whether it's possible for us to move this to |
| 1386 // Focus(). | 1429 // Focus(). |
| 1387 // By default, we clear the native focus. This ensures that no visible native | 1430 // By default, we clear the native focus. This ensures that no visible native |
| 1388 // view as the focus and that we still receive keyboard inputs. | 1431 // view as the focus and that we still receive keyboard inputs. |
| 1389 FocusManager* focus_manager = GetFocusManager(); | 1432 FocusManager* focus_manager = GetFocusManager(); |
| 1390 if (focus_manager) | 1433 if (focus_manager) |
| 1391 focus_manager->ClearNativeFocus(); | 1434 focus_manager->ClearNativeFocus(); |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1981 | 2024 |
| 1982 SchedulePaint(); | 2025 SchedulePaint(); |
| 1983 | 2026 |
| 1984 Widget* widget = GetWidget(); | 2027 Widget* widget = GetWidget(); |
| 1985 if (widget) | 2028 if (widget) |
| 1986 widget->UpdateRootLayers(); | 2029 widget->UpdateRootLayers(); |
| 1987 } | 2030 } |
| 1988 | 2031 |
| 1989 // Input ----------------------------------------------------------------------- | 2032 // Input ----------------------------------------------------------------------- |
| 1990 | 2033 |
| 1991 bool View::ProcessMousePressed(const ui::MouseEvent& event, | 2034 bool View::ProcessMousePressed(const ui::MouseEvent& event) { |
| 1992 DragInfo* drag_info) { | |
| 1993 int drag_operations = | 2035 int drag_operations = |
| 1994 (enabled_ && event.IsOnlyLeftMouseButton() && | 2036 (enabled_ && event.IsOnlyLeftMouseButton() && |
| 1995 HitTestPoint(event.location())) ? | 2037 HitTestPoint(event.location())) ? |
| 1996 GetDragOperations(event.location()) : 0; | 2038 GetDragOperations(event.location()) : 0; |
| 1997 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? | 2039 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? |
| 1998 context_menu_controller_ : 0; | 2040 context_menu_controller_ : 0; |
| 1999 | 2041 |
| 2000 const bool enabled = enabled_; | 2042 const bool enabled = enabled_; |
| 2001 const bool result = OnMousePressed(event); | 2043 const bool result = OnMousePressed(event); |
| 2002 // WARNING: we may have been deleted, don't use any View variables. | 2044 // WARNING: we may have been deleted, don't use any View variables. |
| 2003 | 2045 |
| 2004 if (!enabled) | 2046 if (!enabled) |
| 2005 return result; | 2047 return result; |
| 2006 | 2048 |
| 2007 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { | 2049 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { |
| 2008 drag_info->PossibleDrag(event.location()); | 2050 GetDragInfo()->PossibleDrag(event.location()); |
| 2009 return true; | 2051 return true; |
| 2010 } | 2052 } |
| 2011 return !!context_menu_controller || result; | 2053 return !!context_menu_controller || result; |
| 2012 } | 2054 } |
| 2013 | 2055 |
| 2014 bool View::ProcessMouseDragged(const ui::MouseEvent& event, | 2056 bool View::ProcessMouseDragged(const ui::MouseEvent& event) { |
| 2015 DragInfo* drag_info) { | |
| 2016 // Copy the field, that way if we're deleted after drag and drop no harm is | 2057 // Copy the field, that way if we're deleted after drag and drop no harm is |
| 2017 // done. | 2058 // done. |
| 2018 ContextMenuController* context_menu_controller = context_menu_controller_; | 2059 ContextMenuController* context_menu_controller = context_menu_controller_; |
| 2019 const bool possible_drag = drag_info->possible_drag; | 2060 const bool possible_drag = GetDragInfo()->possible_drag; |
| 2020 if (possible_drag && | 2061 if (possible_drag && |
| 2021 ExceededDragThreshold(drag_info->start_pt - event.location())) { | 2062 ExceededDragThreshold(GetDragInfo()->start_pt - event.location())) { |
| 2022 if (!drag_controller_ || | 2063 if (!drag_controller_ || |
| 2023 drag_controller_->CanStartDragForView( | 2064 drag_controller_->CanStartDragForView( |
| 2024 this, drag_info->start_pt, event.location())) { | 2065 this, GetDragInfo()->start_pt, event.location())) { |
| 2025 DoDrag(event, drag_info->start_pt, | 2066 DoDrag(event, GetDragInfo()->start_pt, |
| 2026 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); | 2067 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); |
| 2027 } | 2068 } |
| 2028 } else { | 2069 } else { |
| 2029 if (OnMouseDragged(event)) | 2070 if (OnMouseDragged(event)) |
| 2030 return true; | 2071 return true; |
| 2031 // Fall through to return value based on context menu controller. | 2072 // Fall through to return value based on context menu controller. |
| 2032 } | 2073 } |
| 2033 // WARNING: we may have been deleted. | 2074 // WARNING: we may have been deleted. |
| 2034 return (context_menu_controller != NULL) || possible_drag; | 2075 return (context_menu_controller != NULL) || possible_drag; |
| 2035 } | 2076 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2189 ConvertPointToWidget(this, &widget_location); | 2230 ConvertPointToWidget(this, &widget_location); |
| 2190 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2231 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
| 2191 source); | 2232 source); |
| 2192 return true; | 2233 return true; |
| 2193 #else | 2234 #else |
| 2194 return false; | 2235 return false; |
| 2195 #endif // !defined(OS_MACOSX) | 2236 #endif // !defined(OS_MACOSX) |
| 2196 } | 2237 } |
| 2197 | 2238 |
| 2198 } // namespace views | 2239 } // namespace views |
| OLD | NEW |