Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 std::string kSubMenuIdentifier = " >"; | |
|
tkent
2014/08/05 08:50:10
We don't allow static initialization of classes.
k
pals
2014/08/05 09:02:24
Done.
| |
| 126 const std::string kSubMenuDepthIdentifier = "_"; | |
| 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 std::string depthPrefix(unsigned depth) | |
| 134 { | |
| 135 if (depth < 1) | |
| 136 return std::string(); | |
| 137 | |
| 138 std::string prefix; | |
| 139 for (size_t i = 0; i < depth; ++i) { | |
| 140 prefix += kSubMenuDepthIdentifier; | |
| 141 } | |
| 142 return std::string(prefix); | |
| 143 } | |
| 144 | |
| 145 void PopulateCustomItems(const WebVector<WebMenuItemInfo>& customItems, | |
| 146 std::vector<std::string>& strings, unsigned depth) { | |
|
tkent
2014/08/05 08:50:10
Please make the third argument |const std::string&
pals
2014/08/05 09:02:24
Done. Thanks
| |
| 147 for (size_t i = 0; i < customItems.size(); ++i) { | |
| 148 if (customItems[i].type == blink::WebMenuItemInfo::SubMenu) { | |
| 149 unsigned newDepth = depth + 1; | |
| 150 strings.push_back(depthPrefix(newDepth) + customItems[i].label.utf8() + kS ubMenuIdentifier); | |
|
tkent
2014/08/05 08:50:10
|depthPrefix(newDepth) +| -> |prefix +|
pals
2014/08/05 09:02:24
Done.
| |
| 151 PopulateCustomItems(customItems[i].subMenuItems, strings, newDepth); | |
|
tkent
2014/08/05 08:50:10
|newDepth| -> |prefix + kSubMenuDepthIdentifier|
pals
2014/08/05 09:02:24
Done.
| |
| 152 } else { | |
| 153 strings.push_back(depthPrefix(depth) + customItems[i].label.utf8()); | |
|
tkent
2014/08/05 08:50:11
|depthPrefix(newDepth) +| -> |prefix +|
pals
2014/08/05 09:02:24
Done.
| |
| 154 } | |
| 155 } | |
| 156 } | |
| 157 | |
| 130 // Because actual context menu is implemented by the browser side, | 158 // Because actual context menu is implemented by the browser side, |
| 131 // this function does only what LayoutTests are expecting: | 159 // this function does only what LayoutTests are expecting: |
| 132 // - Many test checks the count of items. So returning non-zero value makes | 160 // - Many test checks the count of items. So returning non-zero value makes |
| 133 // sense. | 161 // sense. |
| 134 // - Some test compares the count before and after some action. So changing the | 162 // - 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 | 163 // count based on flags also makes sense. This function is doing such for some |
| 136 // flags. | 164 // flags. |
| 137 // - Some test even checks actual string content. So providing it would be also | 165 // - Some test even checks actual string content. So providing it would be also |
| 138 // helpful. | 166 // helpful. |
| 139 std::vector<std::string> MakeMenuItemStringsFor( | 167 std::vector<std::string> MakeMenuItemStringsFor( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 165 "<separator>", | 193 "<separator>", |
| 166 0 | 194 0 |
| 167 }; | 195 }; |
| 168 | 196 |
| 169 // This is possible because mouse events are cancelleable. | 197 // This is possible because mouse events are cancelleable. |
| 170 if (!context_menu) | 198 if (!context_menu) |
| 171 return std::vector<std::string>(); | 199 return std::vector<std::string>(); |
| 172 | 200 |
| 173 std::vector<std::string> strings; | 201 std::vector<std::string> strings; |
| 174 | 202 |
| 203 // Populate custom menu items if provided by the WebCore internals. | |
|
tkent
2014/08/05 08:50:11
|WebCore| is an obsolete name.
"provided by Blink
pals
2014/08/05 09:02:24
Done.
| |
| 204 PopulateCustomItems(context_menu->customItems, strings, 0); | |
|
tkent
2014/08/05 08:50:10
|0| -> |""|
pals
2014/08/05 09:02:24
Done.
| |
| 205 | |
| 175 if (context_menu->isEditable) { | 206 if (context_menu->isEditable) { |
| 176 for (const char** item = kEditableMenuStrings; *item; ++item) { | 207 for (const char** item = kEditableMenuStrings; *item; ++item) { |
| 177 strings.push_back(*item); | 208 strings.push_back(*item); |
| 178 } | 209 } |
| 179 WebVector<WebString> suggestions; | 210 WebVector<WebString> suggestions; |
| 180 MockSpellCheck::FillSuggestionList(context_menu->misspelledWord, | 211 MockSpellCheck::FillSuggestionList(context_menu->misspelledWord, |
| 181 &suggestions); | 212 &suggestions); |
| 182 for (size_t i = 0; i < suggestions.size(); ++i) { | 213 for (size_t i = 0; i < suggestions.size(); ++i) { |
| 183 strings.push_back(suggestions[i].utf8()); | 214 strings.push_back(suggestions[i].utf8()); |
| 184 } | 215 } |
| (...skipping 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2258 } | 2289 } |
| 2259 default: | 2290 default: |
| 2260 NOTREACHED(); | 2291 NOTREACHED(); |
| 2261 } | 2292 } |
| 2262 } | 2293 } |
| 2263 | 2294 |
| 2264 replaying_saved_events_ = false; | 2295 replaying_saved_events_ = false; |
| 2265 } | 2296 } |
| 2266 | 2297 |
| 2267 } // namespace content | 2298 } // namespace content |
| OLD | NEW |