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

Side by Side Diff: trunk/src/ui/views/view.cc

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

Powered by Google App Engine
This is Rietveld 408576698