OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 18 matching lines...) Expand all Loading... | |
29 */ | 29 */ |
30 | 30 |
31 #include "web/ContextMenuClientImpl.h" | 31 #include "web/ContextMenuClientImpl.h" |
32 | 32 |
33 #include "bindings/core/v8/ExceptionState.h" | 33 #include "bindings/core/v8/ExceptionState.h" |
34 #include "core/CSSPropertyNames.h" | 34 #include "core/CSSPropertyNames.h" |
35 #include "core/HTMLNames.h" | 35 #include "core/HTMLNames.h" |
36 #include "core/InputTypeNames.h" | 36 #include "core/InputTypeNames.h" |
37 #include "core/css/CSSStyleDeclaration.h" | 37 #include "core/css/CSSStyleDeclaration.h" |
38 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
39 #include "core/dom/ElementTraversal.h" | |
39 #include "core/editing/Editor.h" | 40 #include "core/editing/Editor.h" |
40 #include "core/editing/markers/DocumentMarkerController.h" | 41 #include "core/editing/markers/DocumentMarkerController.h" |
41 #include "core/editing/spellcheck/SpellChecker.h" | 42 #include "core/editing/spellcheck/SpellChecker.h" |
42 #include "core/exported/WebDataSourceImpl.h" | 43 #include "core/exported/WebDataSourceImpl.h" |
43 #include "core/exported/WebViewBase.h" | 44 #include "core/exported/WebViewBase.h" |
44 #include "core/frame/FrameView.h" | 45 #include "core/frame/FrameView.h" |
45 #include "core/frame/Settings.h" | 46 #include "core/frame/Settings.h" |
46 #include "core/frame/VisualViewport.h" | 47 #include "core/frame/VisualViewport.h" |
47 #include "core/frame/WebLocalFrameBase.h" | 48 #include "core/frame/WebLocalFrameBase.h" |
48 #include "core/html/HTMLAnchorElement.h" | 49 #include "core/html/HTMLAnchorElement.h" |
49 #include "core/html/HTMLFormElement.h" | 50 #include "core/html/HTMLFormElement.h" |
51 #include "core/html/HTMLFrameElementBase.h" | |
50 #include "core/html/HTMLImageElement.h" | 52 #include "core/html/HTMLImageElement.h" |
51 #include "core/html/HTMLInputElement.h" | 53 #include "core/html/HTMLInputElement.h" |
52 #include "core/html/HTMLMediaElement.h" | 54 #include "core/html/HTMLMediaElement.h" |
53 #include "core/html/HTMLPlugInElement.h" | 55 #include "core/html/HTMLPlugInElement.h" |
54 #include "core/input/EventHandler.h" | 56 #include "core/input/EventHandler.h" |
55 #include "core/layout/HitTestResult.h" | 57 #include "core/layout/HitTestResult.h" |
56 #include "core/layout/LayoutPart.h" | 58 #include "core/layout/LayoutPart.h" |
57 #include "core/loader/DocumentLoader.h" | 59 #include "core/loader/DocumentLoader.h" |
58 #include "core/loader/FrameLoader.h" | 60 #include "core/loader/FrameLoader.h" |
59 #include "core/loader/HistoryItem.h" | 61 #include "core/loader/HistoryItem.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 const WebContextMenuData& data) { | 193 const WebContextMenuData& data) { |
192 return web_view_->GetPage() | 194 return web_view_->GetPage() |
193 ->GetSettings() | 195 ->GetSettings() |
194 .GetAlwaysShowContextMenuOnTouch() || | 196 .GetAlwaysShowContextMenuOnTouch() || |
195 !data.link_url.IsEmpty() || | 197 !data.link_url.IsEmpty() || |
196 data.media_type == WebContextMenuData::kMediaTypeImage || | 198 data.media_type == WebContextMenuData::kMediaTypeImage || |
197 data.media_type == WebContextMenuData::kMediaTypeVideo || | 199 data.media_type == WebContextMenuData::kMediaTypeVideo || |
198 data.is_editable; | 200 data.is_editable; |
199 } | 201 } |
200 | 202 |
203 static inline HTMLFormElement* AssociatedFormElement(HTMLElement& element) { | |
yosin_UTC9
2017/05/16 09:57:33
nit: s/inline //
tanvir
2017/05/16 13:40:26
Done.
| |
204 if (isHTMLFormElement(element)) | |
205 return &toHTMLFormElement(element); | |
206 return element.formOwner(); | |
207 } | |
208 | |
209 // Scans logically forward from "start", including any child frames. | |
210 static HTMLFormElement* ScanForForm(Node* start) { | |
211 if (!start) | |
212 return 0; | |
yosin_UTC9
2017/05/16 09:57:33
nit: s/0/nullptr/
tanvir
2017/05/16 13:40:26
Done.
| |
213 | |
214 for (HTMLElement& element : Traversal<HTMLElement>::StartsAt( | |
215 start->IsHTMLElement() ? ToHTMLElement(start) | |
216 : Traversal<HTMLElement>::Next(*start))) { | |
217 if (HTMLFormElement* form = AssociatedFormElement(element)) | |
218 return form; | |
219 | |
220 if (IsHTMLFrameElementBase(element)) { | |
221 Node* child_document = ToHTMLFrameElementBase(element).contentDocument(); | |
222 if (HTMLFormElement* frame_result = ScanForForm(child_document)) | |
223 return frame_result; | |
224 } | |
225 } | |
226 return 0; | |
yosin_UTC9
2017/05/16 09:57:33
nit: s/0/nullptr/
tanvir
2017/05/16 13:40:26
Done.
tanvir
2017/05/16 13:40:26
Done.
| |
227 } | |
228 | |
229 // We look for either the form containing the current focus, or for one | |
230 // immediately after it | |
231 static HTMLFormElement* CurrentForm(const FrameSelection& current_selection) { | |
232 // Start looking either at the active (first responder) node, or where the | |
233 // selection is. | |
234 Node* start = current_selection.GetDocument().FocusedElement(); | |
yosin_UTC9
2017/05/16 09:57:33
nit: s/Node*/Node* const/
tanvir
2017/05/16 13:40:26
We are assigning value below to start when !start.
| |
235 if (!start) { | |
236 start = current_selection.ComputeVisibleSelectionInDOMTree() | |
237 .Start() | |
238 .AnchorNode(); | |
239 } | |
240 if (!start) | |
241 return 0; | |
yosin_UTC9
2017/05/16 09:57:33
nit: s/0/nullptr/
tanvir
2017/05/16 13:40:26
Done.
| |
242 | |
243 // Try walking up the node tree to find a form element. | |
244 for (HTMLElement* element = | |
yosin_UTC9
2017/05/16 09:57:33
Let's use NodeTraversal::InclusiveAncestorsOf() to
tanvir
2017/05/16 13:40:26
done. here also const not added as because of line
| |
245 Traversal<HTMLElement>::FirstAncestorOrSelf(*start); | |
246 element; element = Traversal<HTMLElement>::FirstAncestor(*element)) { | |
247 if (HTMLFormElement* form = AssociatedFormElement(*element)) | |
248 return form; | |
249 } | |
250 | |
251 // Try walking forward in the node tree to find a form element. | |
252 return ScanForForm(start); | |
253 } | |
254 | |
201 bool ContextMenuClientImpl::ShowContextMenu(const ContextMenu* default_menu, | 255 bool ContextMenuClientImpl::ShowContextMenu(const ContextMenu* default_menu, |
202 bool from_touch) { | 256 bool from_touch) { |
203 // Displaying the context menu in this function is a big hack as we don't | 257 // Displaying the context menu in this function is a big hack as we don't |
204 // have context, i.e. whether this is being invoked via a script or in | 258 // have context, i.e. whether this is being invoked via a script or in |
205 // response to user input (Mouse event WM_RBUTTONDOWN, | 259 // response to user input (Mouse event WM_RBUTTONDOWN, |
206 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked | 260 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked |
207 // in response to the above input events before popping up the context menu. | 261 // in response to the above input events before popping up the context menu. |
208 if (!ContextMenuAllowedScope::IsContextMenuAllowed()) | 262 if (!ContextMenuAllowedScope::IsContextMenuAllowed()) |
209 return false; | 263 return false; |
210 | 264 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 Vector<String> suggestions; | 422 Vector<String> suggestions; |
369 description.Split('\n', suggestions); | 423 description.Split('\n', suggestions); |
370 data.dictionary_suggestions = suggestions; | 424 data.dictionary_suggestions = suggestions; |
371 } else if (selected_web_frame->TextCheckClient()) { | 425 } else if (selected_web_frame->TextCheckClient()) { |
372 int misspelled_offset, misspelled_length; | 426 int misspelled_offset, misspelled_length; |
373 selected_web_frame->TextCheckClient()->CheckSpelling( | 427 selected_web_frame->TextCheckClient()->CheckSpelling( |
374 data.misspelled_word, misspelled_offset, misspelled_length, | 428 data.misspelled_word, misspelled_offset, misspelled_length, |
375 &data.dictionary_suggestions); | 429 &data.dictionary_suggestions); |
376 } | 430 } |
377 | 431 |
378 HTMLFormElement* form = selected_frame->Selection().CurrentForm(); | 432 HTMLFormElement* form = CurrentForm(selected_frame->Selection()); |
379 if (form && isHTMLInputElement(*r.InnerNode())) { | 433 if (form && isHTMLInputElement(*r.InnerNode())) { |
380 HTMLInputElement& selected_element = toHTMLInputElement(*r.InnerNode()); | 434 HTMLInputElement& selected_element = toHTMLInputElement(*r.InnerNode()); |
381 WebSearchableFormData ws = WebSearchableFormData( | 435 WebSearchableFormData ws = WebSearchableFormData( |
382 WebFormElement(form), WebInputElement(&selected_element)); | 436 WebFormElement(form), WebInputElement(&selected_element)); |
383 if (ws.Url().IsValid()) | 437 if (ws.Url().IsValid()) |
384 data.keyword_url = ws.Url(); | 438 data.keyword_url = ws.Url(); |
385 } | 439 } |
386 } | 440 } |
387 | 441 |
388 if (selected_frame->GetEditor().SelectionHasStyle(CSSPropertyDirection, | 442 if (selected_frame->GetEditor().SelectionHasStyle(CSSPropertyDirection, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 sub_menu_items.Swap(output_items); | 558 sub_menu_items.Swap(output_items); |
505 } | 559 } |
506 | 560 |
507 void ContextMenuClientImpl::PopulateCustomMenuItems( | 561 void ContextMenuClientImpl::PopulateCustomMenuItems( |
508 const ContextMenu* default_menu, | 562 const ContextMenu* default_menu, |
509 WebContextMenuData* data) { | 563 WebContextMenuData* data) { |
510 PopulateSubMenuItems(default_menu->Items(), data->custom_items); | 564 PopulateSubMenuItems(default_menu->Items(), data->custom_items); |
511 } | 565 } |
512 | 566 |
513 } // namespace blink | 567 } // namespace blink |
OLD | NEW |