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

Side by Side Diff: third_party/WebKit/Source/core/editing/FrameSelection.cpp

Issue 2881013003: Move FrameSelection::CurrentForm() to ContextMenuClientImpl (Closed)
Patch Set: updated PS 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "core/editing/commands/TypingCommand.h" 52 #include "core/editing/commands/TypingCommand.h"
53 #include "core/editing/iterators/TextIterator.h" 53 #include "core/editing/iterators/TextIterator.h"
54 #include "core/editing/serializers/Serialization.h" 54 #include "core/editing/serializers/Serialization.h"
55 #include "core/editing/spellcheck/SpellChecker.h" 55 #include "core/editing/spellcheck/SpellChecker.h"
56 #include "core/events/Event.h" 56 #include "core/events/Event.h"
57 #include "core/frame/FrameView.h" 57 #include "core/frame/FrameView.h"
58 #include "core/frame/LocalDOMWindow.h" 58 #include "core/frame/LocalDOMWindow.h"
59 #include "core/frame/LocalFrame.h" 59 #include "core/frame/LocalFrame.h"
60 #include "core/frame/Settings.h" 60 #include "core/frame/Settings.h"
61 #include "core/html/HTMLBodyElement.h" 61 #include "core/html/HTMLBodyElement.h"
62 #include "core/html/HTMLFormElement.h"
63 #include "core/html/HTMLFrameElementBase.h" 62 #include "core/html/HTMLFrameElementBase.h"
64 #include "core/html/HTMLInputElement.h" 63 #include "core/html/HTMLInputElement.h"
65 #include "core/html/HTMLSelectElement.h" 64 #include "core/html/HTMLSelectElement.h"
66 #include "core/input/EventHandler.h" 65 #include "core/input/EventHandler.h"
67 #include "core/layout/HitTestRequest.h" 66 #include "core/layout/HitTestRequest.h"
68 #include "core/layout/HitTestResult.h" 67 #include "core/layout/HitTestResult.h"
69 #include "core/layout/LayoutPart.h" 68 #include "core/layout/LayoutPart.h"
70 #include "core/layout/api/LayoutViewItem.h" 69 #include "core/layout/api/LayoutViewItem.h"
71 #include "core/loader/DocumentLoader.h" 70 #include "core/loader/DocumentLoader.h"
72 #include "core/page/EditorClient.h" 71 #include "core/page/EditorClient.h"
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 FrameView* view = frame_->View(); 934 FrameView* view = frame_->View();
936 LayoutViewItem layout_view = frame_->ContentLayoutItem(); 935 LayoutViewItem layout_view = frame_->ContentLayoutItem();
937 936
938 if (!view || layout_view.IsNull()) 937 if (!view || layout_view.IsNull())
939 return LayoutRect(); 938 return LayoutRect();
940 939
941 view->UpdateLifecycleToLayoutClean(); 940 view->UpdateLifecycleToLayoutClean();
942 return LayoutRect(layout_selection_->SelectionBounds()); 941 return LayoutRect(layout_selection_->SelectionBounds());
943 } 942 }
944 943
945 static inline HTMLFormElement* AssociatedFormElement(HTMLElement& element) {
946 if (isHTMLFormElement(element))
947 return &toHTMLFormElement(element);
948 return element.formOwner();
949 }
950
951 // Scans logically forward from "start", including any child frames.
952 static HTMLFormElement* ScanForForm(Node* start) {
953 if (!start)
954 return 0;
955
956 for (HTMLElement& element : Traversal<HTMLElement>::StartsAt(
957 start->IsHTMLElement() ? ToHTMLElement(start)
958 : Traversal<HTMLElement>::Next(*start))) {
959 if (HTMLFormElement* form = AssociatedFormElement(element))
960 return form;
961
962 if (IsHTMLFrameElementBase(element)) {
963 Node* child_document = ToHTMLFrameElementBase(element).contentDocument();
964 if (HTMLFormElement* frame_result = ScanForForm(child_document))
965 return frame_result;
966 }
967 }
968 return 0;
969 }
970
971 // We look for either the form containing the current focus, or for one
972 // immediately after it
973 HTMLFormElement* FrameSelection::CurrentForm() const {
974 // Start looking either at the active (first responder) node, or where the
975 // selection is.
976 Node* start = GetDocument().FocusedElement();
977 if (!start)
978 start = ComputeVisibleSelectionInDOMTree().Start().AnchorNode();
979 if (!start)
980 return 0;
981
982 // Try walking up the node tree to find a form element.
983 for (HTMLElement* element =
984 Traversal<HTMLElement>::FirstAncestorOrSelf(*start);
985 element; element = Traversal<HTMLElement>::FirstAncestor(*element)) {
986 if (HTMLFormElement* form = AssociatedFormElement(*element))
987 return form;
988 }
989
990 // Try walking forward in the node tree to find a form element.
991 return ScanForForm(start);
992 }
993
994 void FrameSelection::RevealSelection(const ScrollAlignment& alignment, 944 void FrameSelection::RevealSelection(const ScrollAlignment& alignment,
995 RevealExtentOption reveal_extent_option) { 945 RevealExtentOption reveal_extent_option) {
996 DCHECK(IsAvailable()); 946 DCHECK(IsAvailable());
997 947
998 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 948 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
999 // needs to be audited. See http://crbug.com/590369 for more details. 949 // needs to be audited. See http://crbug.com/590369 for more details.
1000 // Calculation of absolute caret bounds requires clean layout. 950 // Calculation of absolute caret bounds requires clean layout.
1001 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); 951 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
1002 952
1003 LayoutRect rect; 953 LayoutRect rect;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 } 1167 }
1218 1168
1219 void showTree(const blink::FrameSelection* sel) { 1169 void showTree(const blink::FrameSelection* sel) {
1220 if (sel) 1170 if (sel)
1221 sel->ShowTreeForThis(); 1171 sel->ShowTreeForThis();
1222 else 1172 else
1223 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1173 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1224 } 1174 }
1225 1175
1226 #endif 1176 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.h ('k') | third_party/WebKit/Source/web/ContextMenuClientImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698