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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 namespace { | 50 namespace { |
51 | 51 |
52 // Whether to use accelerated compositing when necessary (e.g. when a view has a | 52 // Whether to use accelerated compositing when necessary (e.g. when a view has a |
53 // transformation). | 53 // transformation). |
54 #if defined(USE_AURA) | 54 #if defined(USE_AURA) |
55 bool use_acceleration_when_possible = true; | 55 bool use_acceleration_when_possible = true; |
56 #else | 56 #else |
57 bool use_acceleration_when_possible = false; | 57 bool use_acceleration_when_possible = false; |
58 #endif | 58 #endif |
59 | 59 |
| 60 #if defined(OS_WIN) |
| 61 const bool kContextMenuOnMousePress = false; |
| 62 #else |
| 63 const bool kContextMenuOnMousePress = true; |
| 64 #endif |
| 65 |
60 // Saves the drawing state, and restores the state when going out of scope. | 66 // Saves the drawing state, and restores the state when going out of scope. |
61 class ScopedCanvas { | 67 class ScopedCanvas { |
62 public: | 68 public: |
63 explicit ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) { | 69 explicit ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) { |
64 if (canvas_) | 70 if (canvas_) |
65 canvas_->Save(); | 71 canvas_->Save(); |
66 } | 72 } |
67 ~ScopedCanvas() { | 73 ~ScopedCanvas() { |
68 if (canvas_) | 74 if (canvas_) |
69 canvas_->Restore(); | 75 canvas_->Restore(); |
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 | 1129 |
1124 // Context menus --------------------------------------------------------------- | 1130 // Context menus --------------------------------------------------------------- |
1125 | 1131 |
1126 void View::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { | 1132 void View::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { |
1127 if (!context_menu_controller_) | 1133 if (!context_menu_controller_) |
1128 return; | 1134 return; |
1129 | 1135 |
1130 context_menu_controller_->ShowContextMenuForView(this, p); | 1136 context_menu_controller_->ShowContextMenuForView(this, p); |
1131 } | 1137 } |
1132 | 1138 |
| 1139 // static |
| 1140 bool View::ShouldShowContextMenuOnMousePress() { |
| 1141 return kContextMenuOnMousePress; |
| 1142 } |
| 1143 |
1133 // Drag and drop --------------------------------------------------------------- | 1144 // Drag and drop --------------------------------------------------------------- |
1134 | 1145 |
1135 bool View::GetDropFormats( | 1146 bool View::GetDropFormats( |
1136 int* formats, | 1147 int* formats, |
1137 std::set<OSExchangeData::CustomFormat>* custom_formats) { | 1148 std::set<OSExchangeData::CustomFormat>* custom_formats) { |
1138 return false; | 1149 return false; |
1139 } | 1150 } |
1140 | 1151 |
1141 bool View::AreDropTypesRequired() { | 1152 bool View::AreDropTypesRequired() { |
1142 return false; | 1153 return false; |
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2053 | 2064 |
2054 // Input ----------------------------------------------------------------------- | 2065 // Input ----------------------------------------------------------------------- |
2055 | 2066 |
2056 bool View::ProcessMousePressed(const ui::MouseEvent& event) { | 2067 bool View::ProcessMousePressed(const ui::MouseEvent& event) { |
2057 int drag_operations = | 2068 int drag_operations = |
2058 (enabled_ && event.IsOnlyLeftMouseButton() && | 2069 (enabled_ && event.IsOnlyLeftMouseButton() && |
2059 HitTestPoint(event.location())) ? | 2070 HitTestPoint(event.location())) ? |
2060 GetDragOperations(event.location()) : 0; | 2071 GetDragOperations(event.location()) : 0; |
2061 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? | 2072 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? |
2062 context_menu_controller_ : 0; | 2073 context_menu_controller_ : 0; |
| 2074 View::DragInfo* drag_info = GetDragInfo(); |
2063 | 2075 |
2064 const bool enabled = enabled_; | 2076 const bool enabled = enabled_; |
2065 const bool result = OnMousePressed(event); | 2077 const bool result = OnMousePressed(event); |
2066 // WARNING: we may have been deleted, don't use any View variables. | |
2067 | 2078 |
2068 if (!enabled) | 2079 if (!enabled) |
2069 return result; | 2080 return result; |
2070 | 2081 |
| 2082 if (event.IsOnlyRightMouseButton() && context_menu_controller && |
| 2083 kContextMenuOnMousePress) { |
| 2084 // Assume that if there is a context menu controller we won't be deleted |
| 2085 // from mouse pressed. |
| 2086 gfx::Point location(event.location()); |
| 2087 if (HitTestPoint(location)) { |
| 2088 ConvertPointToScreen(this, &location); |
| 2089 ShowContextMenu(location, true); |
| 2090 return true; |
| 2091 } |
| 2092 } |
| 2093 |
| 2094 // WARNING: we may have been deleted, don't use any View variables. |
2071 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { | 2095 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { |
2072 GetDragInfo()->PossibleDrag(event.location()); | 2096 drag_info->PossibleDrag(event.location()); |
2073 return true; | 2097 return true; |
2074 } | 2098 } |
2075 return !!context_menu_controller || result; | 2099 return !!context_menu_controller || result; |
2076 } | 2100 } |
2077 | 2101 |
2078 bool View::ProcessMouseDragged(const ui::MouseEvent& event) { | 2102 bool View::ProcessMouseDragged(const ui::MouseEvent& event) { |
2079 // Copy the field, that way if we're deleted after drag and drop no harm is | 2103 // Copy the field, that way if we're deleted after drag and drop no harm is |
2080 // done. | 2104 // done. |
2081 ContextMenuController* context_menu_controller = context_menu_controller_; | 2105 ContextMenuController* context_menu_controller = context_menu_controller_; |
2082 const bool possible_drag = GetDragInfo()->possible_drag; | 2106 const bool possible_drag = GetDragInfo()->possible_drag; |
2083 if (possible_drag && | 2107 if (possible_drag && |
2084 ExceededDragThreshold(GetDragInfo()->start_pt - event.location())) { | 2108 ExceededDragThreshold(GetDragInfo()->start_pt - event.location())) { |
2085 if (!drag_controller_ || | 2109 if (!drag_controller_ || |
2086 drag_controller_->CanStartDragForView( | 2110 drag_controller_->CanStartDragForView( |
2087 this, GetDragInfo()->start_pt, event.location())) { | 2111 this, GetDragInfo()->start_pt, event.location())) { |
2088 DoDrag(event, GetDragInfo()->start_pt, | 2112 DoDrag(event, GetDragInfo()->start_pt, |
2089 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); | 2113 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); |
2090 } | 2114 } |
2091 } else { | 2115 } else { |
2092 if (OnMouseDragged(event)) | 2116 if (OnMouseDragged(event)) |
2093 return true; | 2117 return true; |
2094 // Fall through to return value based on context menu controller. | 2118 // Fall through to return value based on context menu controller. |
2095 } | 2119 } |
2096 // WARNING: we may have been deleted. | 2120 // WARNING: we may have been deleted. |
2097 return (context_menu_controller != NULL) || possible_drag; | 2121 return (context_menu_controller != NULL) || possible_drag; |
2098 } | 2122 } |
2099 | 2123 |
2100 void View::ProcessMouseReleased(const ui::MouseEvent& event) { | 2124 void View::ProcessMouseReleased(const ui::MouseEvent& event) { |
2101 if (context_menu_controller_ && event.IsOnlyRightMouseButton()) { | 2125 if (!kContextMenuOnMousePress && context_menu_controller_ && |
| 2126 event.IsOnlyRightMouseButton()) { |
2102 // Assume that if there is a context menu controller we won't be deleted | 2127 // Assume that if there is a context menu controller we won't be deleted |
2103 // from mouse released. | 2128 // from mouse released. |
2104 gfx::Point location(event.location()); | 2129 gfx::Point location(event.location()); |
2105 OnMouseReleased(event); | 2130 OnMouseReleased(event); |
2106 if (HitTestPoint(location)) { | 2131 if (HitTestPoint(location)) { |
2107 ConvertPointToScreen(this, &location); | 2132 ConvertPointToScreen(this, &location); |
2108 ShowContextMenu(location, true); | 2133 ShowContextMenu(location, true); |
2109 } | 2134 } |
2110 } else { | 2135 } else { |
2111 OnMouseReleased(event); | 2136 OnMouseReleased(event); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2252 ConvertPointToWidget(this, &widget_location); | 2277 ConvertPointToWidget(this, &widget_location); |
2253 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2278 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
2254 source); | 2279 source); |
2255 return true; | 2280 return true; |
2256 #else | 2281 #else |
2257 return false; | 2282 return false; |
2258 #endif // !defined(OS_MACOSX) | 2283 #endif // !defined(OS_MACOSX) |
2259 } | 2284 } |
2260 | 2285 |
2261 } // namespace views | 2286 } // namespace views |
OLD | NEW |