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

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

Issue 12529012: Context menu on views must show on mouse down for non-WIN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 7 years, 9 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
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
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 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 2061
2056 // Input ----------------------------------------------------------------------- 2062 // Input -----------------------------------------------------------------------
2057 2063
2058 bool View::ProcessMousePressed(const ui::MouseEvent& event) { 2064 bool View::ProcessMousePressed(const ui::MouseEvent& event) {
2059 int drag_operations = 2065 int drag_operations =
2060 (enabled_ && event.IsOnlyLeftMouseButton() && 2066 (enabled_ && event.IsOnlyLeftMouseButton() &&
2061 HitTestPoint(event.location())) ? 2067 HitTestPoint(event.location())) ?
2062 GetDragOperations(event.location()) : 0; 2068 GetDragOperations(event.location()) : 0;
2063 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? 2069 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ?
2064 context_menu_controller_ : 0; 2070 context_menu_controller_ : 0;
2071 View::DragInfo* drag_info = GetDragInfo();
2065 2072
2066 const bool enabled = enabled_; 2073 const bool enabled = enabled_;
2067 const bool result = OnMousePressed(event); 2074 const bool result = OnMousePressed(event);
2068 // WARNING: we may have been deleted, don't use any View variables. 2075 // WARNING: we may have been deleted, don't use any View variables.
2069 2076
2070 if (!enabled) 2077 if (!enabled)
2071 return result; 2078 return result;
2072 2079
2080 if (event.IsOnlyRightMouseButton() && context_menu_controller &&
2081 kContextMenuOnMousePress) {
2082 // Assume that if there is a context menu controller we won't be deleted
2083 // from mouse pressed.
2084 gfx::Point location(event.location());
2085 if (HitTestPoint(location)) {
2086 ConvertPointToScreen(this, &location);
2087 ShowContextMenu(location, true);
2088 return true;
2089 }
2090 }
2091
2073 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { 2092 if (drag_operations != ui::DragDropTypes::DRAG_NONE) {
2074 GetDragInfo()->PossibleDrag(event.location()); 2093 drag_info->PossibleDrag(event.location());
2075 return true; 2094 return true;
2076 } 2095 }
2077 return !!context_menu_controller || result; 2096 return !!context_menu_controller || result;
2078 } 2097 }
2079 2098
2080 bool View::ProcessMouseDragged(const ui::MouseEvent& event) { 2099 bool View::ProcessMouseDragged(const ui::MouseEvent& event) {
2081 // Copy the field, that way if we're deleted after drag and drop no harm is 2100 // Copy the field, that way if we're deleted after drag and drop no harm is
2082 // done. 2101 // done.
2083 ContextMenuController* context_menu_controller = context_menu_controller_; 2102 ContextMenuController* context_menu_controller = context_menu_controller_;
2084 const bool possible_drag = GetDragInfo()->possible_drag; 2103 const bool possible_drag = GetDragInfo()->possible_drag;
2085 if (possible_drag && 2104 if (possible_drag &&
2086 ExceededDragThreshold(GetDragInfo()->start_pt - event.location())) { 2105 ExceededDragThreshold(GetDragInfo()->start_pt - event.location())) {
2087 if (!drag_controller_ || 2106 if (!drag_controller_ ||
2088 drag_controller_->CanStartDragForView( 2107 drag_controller_->CanStartDragForView(
2089 this, GetDragInfo()->start_pt, event.location())) { 2108 this, GetDragInfo()->start_pt, event.location())) {
2090 DoDrag(event, GetDragInfo()->start_pt, 2109 DoDrag(event, GetDragInfo()->start_pt,
2091 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); 2110 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
2092 } 2111 }
2093 } else { 2112 } else {
2094 if (OnMouseDragged(event)) 2113 if (OnMouseDragged(event))
2095 return true; 2114 return true;
2096 // Fall through to return value based on context menu controller. 2115 // Fall through to return value based on context menu controller.
2097 } 2116 }
2098 // WARNING: we may have been deleted. 2117 // WARNING: we may have been deleted.
2099 return (context_menu_controller != NULL) || possible_drag; 2118 return (context_menu_controller != NULL) || possible_drag;
2100 } 2119 }
2101 2120
2102 void View::ProcessMouseReleased(const ui::MouseEvent& event) { 2121 void View::ProcessMouseReleased(const ui::MouseEvent& event) {
2103 if (context_menu_controller_ && event.IsOnlyRightMouseButton()) { 2122 if (!kContextMenuOnMousePress && context_menu_controller_ &&
2123 event.IsOnlyRightMouseButton()) {
2104 // Assume that if there is a context menu controller we won't be deleted 2124 // Assume that if there is a context menu controller we won't be deleted
2105 // from mouse released. 2125 // from mouse released.
2106 gfx::Point location(event.location()); 2126 gfx::Point location(event.location());
2107 OnMouseReleased(event); 2127 OnMouseReleased(event);
2108 if (HitTestPoint(location)) { 2128 if (HitTestPoint(location)) {
2109 ConvertPointToScreen(this, &location); 2129 ConvertPointToScreen(this, &location);
2110 ShowContextMenu(location, true); 2130 ShowContextMenu(location, true);
2111 } 2131 }
2112 } else { 2132 } else {
2113 OnMouseReleased(event); 2133 OnMouseReleased(event);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 ConvertPointToWidget(this, &widget_location); 2274 ConvertPointToWidget(this, &widget_location);
2255 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, 2275 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations,
2256 source); 2276 source);
2257 return true; 2277 return true;
2258 #else 2278 #else
2259 return false; 2279 return false;
2260 #endif // !defined(OS_MACOSX) 2280 #endif // !defined(OS_MACOSX)
2261 } 2281 }
2262 2282
2263 } // namespace views 2283 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698