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

Unified Diff: third_party/WebKit/Source/web/ContextMenuClientImpl.cpp

Issue 2881013003: Move FrameSelection::CurrentForm() to ContextMenuClientImpl (Closed)
Patch Set: updated patch Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/web/ContextMenuClientImpl.cpp
diff --git a/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp b/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp
index 8654ed996bc1b1ebcef4f540fb7ee01c990c8f27..ce1e6a42ae6eca737a1b821aafad01e9242177bd 100644
--- a/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp
+++ b/third_party/WebKit/Source/web/ContextMenuClientImpl.cpp
@@ -36,6 +36,7 @@
#include "core/InputTypeNames.h"
#include "core/css/CSSStyleDeclaration.h"
#include "core/dom/Document.h"
+#include "core/dom/ElementTraversal.h"
#include "core/editing/Editor.h"
#include "core/editing/markers/DocumentMarkerController.h"
#include "core/editing/spellcheck/SpellChecker.h"
@@ -47,6 +48,7 @@
#include "core/frame/WebLocalFrameBase.h"
#include "core/html/HTMLAnchorElement.h"
#include "core/html/HTMLFormElement.h"
+#include "core/html/HTMLFrameElementBase.h"
#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLMediaElement.h"
@@ -198,6 +200,58 @@ bool ContextMenuClientImpl::ShouldShowContextMenuFromTouch(
data.is_editable;
}
+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.
+ if (isHTMLFormElement(element))
+ return &toHTMLFormElement(element);
+ return element.formOwner();
+}
+
+// Scans logically forward from "start", including any child frames.
+static HTMLFormElement* ScanForForm(Node* start) {
+ if (!start)
+ return 0;
yosin_UTC9 2017/05/16 09:57:33 nit: s/0/nullptr/
tanvir 2017/05/16 13:40:26 Done.
+
+ for (HTMLElement& element : Traversal<HTMLElement>::StartsAt(
+ start->IsHTMLElement() ? ToHTMLElement(start)
+ : Traversal<HTMLElement>::Next(*start))) {
+ if (HTMLFormElement* form = AssociatedFormElement(element))
+ return form;
+
+ if (IsHTMLFrameElementBase(element)) {
+ Node* child_document = ToHTMLFrameElementBase(element).contentDocument();
+ if (HTMLFormElement* frame_result = ScanForForm(child_document))
+ return frame_result;
+ }
+ }
+ 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.
+}
+
+// We look for either the form containing the current focus, or for one
+// immediately after it
+static HTMLFormElement* CurrentForm(const FrameSelection& current_selection) {
+ // Start looking either at the active (first responder) node, or where the
+ // selection is.
+ 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.
+ if (!start) {
+ start = current_selection.ComputeVisibleSelectionInDOMTree()
+ .Start()
+ .AnchorNode();
+ }
+ if (!start)
+ return 0;
yosin_UTC9 2017/05/16 09:57:33 nit: s/0/nullptr/
tanvir 2017/05/16 13:40:26 Done.
+
+ // Try walking up the node tree to find a form element.
+ 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
+ Traversal<HTMLElement>::FirstAncestorOrSelf(*start);
+ element; element = Traversal<HTMLElement>::FirstAncestor(*element)) {
+ if (HTMLFormElement* form = AssociatedFormElement(*element))
+ return form;
+ }
+
+ // Try walking forward in the node tree to find a form element.
+ return ScanForForm(start);
+}
+
bool ContextMenuClientImpl::ShowContextMenu(const ContextMenu* default_menu,
bool from_touch) {
// Displaying the context menu in this function is a big hack as we don't
@@ -375,7 +429,7 @@ bool ContextMenuClientImpl::ShowContextMenu(const ContextMenu* default_menu,
&data.dictionary_suggestions);
}
- HTMLFormElement* form = selected_frame->Selection().CurrentForm();
+ HTMLFormElement* form = CurrentForm(selected_frame->Selection());
if (form && isHTMLInputElement(*r.InnerNode())) {
HTMLInputElement& selected_element = toHTMLInputElement(*r.InnerNode());
WebSearchableFormData ws = WebSearchableFormData(
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698