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

Side by Side Diff: content/shell/renderer/test_runner/event_sender.cc

Issue 438193003: Updating MakeMenuItemStringsFor() to include custom items if provided by blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/shell/renderer/test_runner/event_sender.h" 5 #include "content/shell/renderer/test_runner/event_sender.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "content/public/common/page_zoom.h" 10 #include "content/public/common/page_zoom.h"
(...skipping 14 matching lines...) Expand all
25 #include "v8/include/v8.h" 25 #include "v8/include/v8.h"
26 26
27 using blink::WebContextMenuData; 27 using blink::WebContextMenuData;
28 using blink::WebDragData; 28 using blink::WebDragData;
29 using blink::WebDragOperationsMask; 29 using blink::WebDragOperationsMask;
30 using blink::WebFloatPoint; 30 using blink::WebFloatPoint;
31 using blink::WebFrame; 31 using blink::WebFrame;
32 using blink::WebGestureEvent; 32 using blink::WebGestureEvent;
33 using blink::WebInputEvent; 33 using blink::WebInputEvent;
34 using blink::WebKeyboardEvent; 34 using blink::WebKeyboardEvent;
35 using blink::WebMenuItemInfo;
35 using blink::WebMouseEvent; 36 using blink::WebMouseEvent;
36 using blink::WebMouseWheelEvent; 37 using blink::WebMouseWheelEvent;
37 using blink::WebPoint; 38 using blink::WebPoint;
38 using blink::WebString; 39 using blink::WebString;
39 using blink::WebTouchEvent; 40 using blink::WebTouchEvent;
40 using blink::WebTouchPoint; 41 using blink::WebTouchPoint;
41 using blink::WebVector; 42 using blink::WebVector;
42 using blink::WebView; 43 using blink::WebView;
43 44
44 namespace content { 45 namespace content {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 gin::Converter<std::vector<std::string> >::FromV8( 115 gin::Converter<std::vector<std::string> >::FromV8(
115 NULL, value, &modifier_names); 116 NULL, value, &modifier_names);
116 } 117 }
117 return GetKeyModifiers(modifier_names); 118 return GetKeyModifiers(modifier_names);
118 } 119 }
119 120
120 // Maximum distance (in space and time) for a mouse click to register as a 121 // Maximum distance (in space and time) for a mouse click to register as a
121 // double or triple click. 122 // double or triple click.
122 const double kMultipleClickTimeSec = 1; 123 const double kMultipleClickTimeSec = 1;
123 const int kMultipleClickRadiusPixels = 5; 124 const int kMultipleClickRadiusPixels = 5;
125 const char kSubMenuDepthIdentifier[] = "_";
126 const char kSubMenuIdentifier[] = " >";
124 127
125 bool OutsideMultiClickRadius(const WebPoint& a, const WebPoint& b) { 128 bool OutsideMultiClickRadius(const WebPoint& a, const WebPoint& b) {
126 return ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) > 129 return ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) >
127 kMultipleClickRadiusPixels * kMultipleClickRadiusPixels; 130 kMultipleClickRadiusPixels * kMultipleClickRadiusPixels;
128 } 131 }
129 132
133 void PopulateCustomItems(const WebVector<WebMenuItemInfo>& customItems,
134 const std::string& prefix, std::vector<std::string>* strings) {
135 for (size_t i = 0; i < customItems.size(); ++i) {
136 if (customItems[i].type == blink::WebMenuItemInfo::SubMenu) {
137 strings->push_back(prefix + customItems[i].label.utf8() +
138 kSubMenuIdentifier);
139 PopulateCustomItems(customItems[i].subMenuItems, prefix +
140 kSubMenuDepthIdentifier, strings);
141 } else {
142 strings->push_back(prefix + customItems[i].label.utf8());
143 }
144 }
145 }
146
130 // Because actual context menu is implemented by the browser side, 147 // Because actual context menu is implemented by the browser side,
131 // this function does only what LayoutTests are expecting: 148 // this function does only what LayoutTests are expecting:
132 // - Many test checks the count of items. So returning non-zero value makes 149 // - Many test checks the count of items. So returning non-zero value makes
133 // sense. 150 // sense.
134 // - Some test compares the count before and after some action. So changing the 151 // - Some test compares the count before and after some action. So changing the
135 // count based on flags also makes sense. This function is doing such for some 152 // count based on flags also makes sense. This function is doing such for some
136 // flags. 153 // flags.
137 // - Some test even checks actual string content. So providing it would be also 154 // - Some test even checks actual string content. So providing it would be also
138 // helpful. 155 // helpful.
139 std::vector<std::string> MakeMenuItemStringsFor( 156 std::vector<std::string> MakeMenuItemStringsFor(
(...skipping 25 matching lines...) Expand all
165 "<separator>", 182 "<separator>",
166 0 183 0
167 }; 184 };
168 185
169 // This is possible because mouse events are cancelleable. 186 // This is possible because mouse events are cancelleable.
170 if (!context_menu) 187 if (!context_menu)
171 return std::vector<std::string>(); 188 return std::vector<std::string>();
172 189
173 std::vector<std::string> strings; 190 std::vector<std::string> strings;
174 191
192 // Populate custom menu items if provided by blink.
193 PopulateCustomItems(context_menu->customItems, "", &strings);
194
175 if (context_menu->isEditable) { 195 if (context_menu->isEditable) {
176 for (const char** item = kEditableMenuStrings; *item; ++item) { 196 for (const char** item = kEditableMenuStrings; *item; ++item) {
177 strings.push_back(*item); 197 strings.push_back(*item);
178 } 198 }
179 WebVector<WebString> suggestions; 199 WebVector<WebString> suggestions;
180 MockSpellCheck::FillSuggestionList(context_menu->misspelledWord, 200 MockSpellCheck::FillSuggestionList(context_menu->misspelledWord,
181 &suggestions); 201 &suggestions);
182 for (size_t i = 0; i < suggestions.size(); ++i) { 202 for (size_t i = 0; i < suggestions.size(); ++i) {
183 strings.push_back(suggestions[i].utf8()); 203 strings.push_back(suggestions[i].utf8());
184 } 204 }
(...skipping 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after
2258 } 2278 }
2259 default: 2279 default:
2260 NOTREACHED(); 2280 NOTREACHED();
2261 } 2281 }
2262 } 2282 }
2263 2283
2264 replaying_saved_events_ = false; 2284 replaying_saved_events_ = false;
2265 } 2285 }
2266 2286
2267 } // namespace content 2287 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698