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

Side by Side Diff: Source/core/page/FocusController.cpp

Issue 219903002: Revert 170347 "Convert HTMLFrameOwnerElement and FocusController..." (Closed) Base URL: svn://svn.chromium.org/blink/branches/chromium/1917/
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/page/FocusController.h ('k') | Source/core/page/PageSerializer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nuanti Ltd. 3 * Copyright (C) 2008 Nuanti Ltd.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return &m_rootTreeScope->rootNode(); 80 return &m_rootTreeScope->rootNode();
81 } 81 }
82 82
83 Element* FocusNavigationScope::owner() const 83 Element* FocusNavigationScope::owner() const
84 { 84 {
85 Node* root = rootNode(); 85 Node* root = rootNode();
86 if (root->isShadowRoot()) { 86 if (root->isShadowRoot()) {
87 ShadowRoot* shadowRoot = toShadowRoot(root); 87 ShadowRoot* shadowRoot = toShadowRoot(root);
88 return shadowRoot->isYoungest() ? shadowRoot->host() : shadowRoot->shado wInsertionPointOfYoungerShadowRoot(); 88 return shadowRoot->isYoungest() ? shadowRoot->host() : shadowRoot->shado wInsertionPointOfYoungerShadowRoot();
89 } 89 }
90 if (Frame* frame = root->document().frame()) 90 if (LocalFrame* frame = root->document().frame())
91 return frame->ownerElement(); 91 return frame->ownerElement();
92 return 0; 92 return 0;
93 } 93 }
94 94
95 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node* node) 95 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node* node)
96 { 96 {
97 ASSERT(node); 97 ASSERT(node);
98 Node* root = node; 98 Node* root = node;
99 for (Node* n = node; n; n = n->parentNode()) 99 for (Node* n = node; n; n = n->parentNode())
100 root = n; 100 root = n;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 , m_isChangingFocusedFrame(false) 224 , m_isChangingFocusedFrame(false)
225 , m_containingWindowIsVisible(false) 225 , m_containingWindowIsVisible(false)
226 { 226 {
227 } 227 }
228 228
229 PassOwnPtr<FocusController> FocusController::create(Page* page) 229 PassOwnPtr<FocusController> FocusController::create(Page* page)
230 { 230 {
231 return adoptPtr(new FocusController(page)); 231 return adoptPtr(new FocusController(page));
232 } 232 }
233 233
234 void FocusController::setFocusedFrame(PassRefPtr<Frame> frame) 234 void FocusController::setFocusedFrame(PassRefPtr<LocalFrame> frame)
235 { 235 {
236 ASSERT(!frame || frame->page() == m_page); 236 ASSERT(!frame || frame->page() == m_page);
237 if (m_focusedFrame == frame || m_isChangingFocusedFrame) 237 if (m_focusedFrame == frame || m_isChangingFocusedFrame)
238 return; 238 return;
239 239
240 m_isChangingFocusedFrame = true; 240 m_isChangingFocusedFrame = true;
241 241
242 RefPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFram e()) ? toLocalFrame(m_focusedFrame.get()) : 0; 242 RefPtr<LocalFrame> oldFrame = m_focusedFrame;
243 RefPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFram e(frame.get()) : 0; 243 RefPtr<LocalFrame> newFrame = frame;
244 244
245 m_focusedFrame = frame.get(); 245 m_focusedFrame = newFrame;
246 246
247 // Now that the frame is updated, fire events and update the selection focus ed states of both frames. 247 // Now that the frame is updated, fire events and update the selection focus ed states of both frames.
248 if (oldFrame && oldFrame->view()) { 248 if (oldFrame && oldFrame->view()) {
249 oldFrame->selection().setFocused(false); 249 oldFrame->selection().setFocused(false);
250 oldFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::blur) ); 250 oldFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::blur) );
251 } 251 }
252 252
253 if (newFrame && newFrame->view() && isFocused()) { 253 if (newFrame && newFrame->view() && isFocused()) {
254 newFrame->selection().setFocused(true); 254 newFrame->selection().setFocused(true);
255 newFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::focus )); 255 newFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::focus ));
256 } 256 }
257 257
258 m_isChangingFocusedFrame = false; 258 m_isChangingFocusedFrame = false;
259 259
260 m_page->chrome().client().focusedFrameChanged(newFrame.get()); 260 m_page->chrome().client().focusedFrameChanged(newFrame.get());
261 } 261 }
262 262
263 Frame* FocusController::focusedOrMainFrame() const 263 LocalFrame* FocusController::focusedOrMainFrame() const
264 { 264 {
265 if (Frame* frame = focusedFrame()) 265 if (LocalFrame* frame = focusedFrame())
266 return frame; 266 return frame;
267 return m_page->mainFrame(); 267 return m_page->mainFrame();
268 } 268 }
269 269
270 void FocusController::setFocused(bool focused) 270 void FocusController::setFocused(bool focused)
271 { 271 {
272 if (isFocused() == focused) 272 if (isFocused() == focused)
273 return; 273 return;
274 274
275 m_isFocused = focused; 275 m_isFocused = focused;
276 276
277 if (!m_isFocused && focusedOrMainFrame()->isLocalFrame()) 277 if (!m_isFocused)
278 toLocalFrame(focusedOrMainFrame())->eventHandler().stopAutoscroll(); 278 focusedOrMainFrame()->eventHandler().stopAutoscroll();
279 279
280 if (!m_focusedFrame) 280 if (!m_focusedFrame)
281 setFocusedFrame(m_page->mainFrame()); 281 setFocusedFrame(m_page->mainFrame());
282 282
283 // setFocusedFrame above might reject to update m_focusedFrame, or 283 // setFocusedFrame above might reject to update m_focusedFrame, or
284 // m_focusedFrame might be changed by blur/focus event handlers. 284 // m_focusedFrame might be changed by blur/focus event handlers.
285 if (m_focusedFrame && m_focusedFrame->isLocalFrame() && toLocalFrame(m_focus edFrame.get())->view()) { 285 if (m_focusedFrame && m_focusedFrame->view()) {
286 toLocalFrame(m_focusedFrame.get())->selection().setFocused(focused); 286 m_focusedFrame->selection().setFocused(focused);
287 dispatchEventsOnWindowAndFocusedNode(toLocalFrame(m_focusedFrame.get())- >document(), focused); 287 dispatchEventsOnWindowAndFocusedNode(m_focusedFrame->document(), focused );
288 } 288 }
289 } 289 }
290 290
291 Node* FocusController::findFocusableNodeDecendingDownIntoFrameDocument(FocusType type, Node* node) 291 Node* FocusController::findFocusableNodeDecendingDownIntoFrameDocument(FocusType type, Node* node)
292 { 292 {
293 // The node we found might be a HTMLFrameOwnerElement, so descend down the t ree until we find either: 293 // The node we found might be a HTMLFrameOwnerElement, so descend down the t ree until we find either:
294 // 1) a focusable node, or 294 // 1) a focusable node, or
295 // 2) the deepest-nested HTMLFrameOwnerElement. 295 // 2) the deepest-nested HTMLFrameOwnerElement.
296 while (node && node->isFrameOwnerElement()) { 296 while (node && node->isFrameOwnerElement()) {
297 HTMLFrameOwnerElement* owner = toHTMLFrameOwnerElement(node); 297 HTMLFrameOwnerElement* owner = toHTMLFrameOwnerElement(node);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 return advanceFocusDirectionally(type); 332 return advanceFocusDirectionally(type);
333 default: 333 default:
334 ASSERT_NOT_REACHED(); 334 ASSERT_NOT_REACHED();
335 } 335 }
336 336
337 return false; 337 return false;
338 } 338 }
339 339
340 bool FocusController::advanceFocusInDocumentOrder(FocusType type, bool initialFo cus) 340 bool FocusController::advanceFocusInDocumentOrder(FocusType type, bool initialFo cus)
341 { 341 {
342 // FIXME: Focus advancement won't work with externally rendered frames until after 342 LocalFrame* frame = focusedOrMainFrame();
343 // inter-frame focus control is moved out of Blink.
344 if (!focusedOrMainFrame()->isLocalFrame())
345 return false;
346 LocalFrame* frame = toLocalFrame(focusedOrMainFrame());
347 ASSERT(frame); 343 ASSERT(frame);
348 Document* document = frame->document(); 344 Document* document = frame->document();
349 345
350 Node* currentNode = document->focusedElement(); 346 Node* currentNode = document->focusedElement();
351 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself 347 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself
352 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn abled(); 348 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn abled();
353 349
354 if (caretBrowsing && !currentNode) 350 if (caretBrowsing && !currentNode)
355 currentNode = frame->selection().start().deprecatedNode(); 351 currentNode = frame->selection().start().deprecatedNode();
356 352
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 if (Node* shadowAncestorNode = root->deprecatedShadowAncestorNode()) { 618 if (Node* shadowAncestorNode = root->deprecatedShadowAncestorNode()) {
623 if (!isHTMLInputElement(*shadowAncestorNode) && !isHTMLTextAreaE lement(*shadowAncestorNode)) 619 if (!isHTMLInputElement(*shadowAncestorNode) && !isHTMLTextAreaE lement(*shadowAncestorNode))
624 return; 620 return;
625 } 621 }
626 } 622 }
627 } 623 }
628 624
629 selection.clear(); 625 selection.clear();
630 } 626 }
631 627
632 bool FocusController::setFocusedElement(Element* element, PassRefPtr<Frame> newF ocusedFrame, FocusType type) 628 bool FocusController::setFocusedElement(Element* element, PassRefPtr<LocalFrame> newFocusedFrame, FocusType type)
633 { 629 {
634 RefPtr<LocalFrame> oldFocusedFrame = toLocalFrame(focusedFrame()); 630 RefPtr<LocalFrame> oldFocusedFrame = focusedFrame();
635 RefPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : 0; 631 RefPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : 0;
636 632
637 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : 0 ; 633 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : 0 ;
638 if (element && oldFocusedElement == element) 634 if (element && oldFocusedElement == element)
639 return true; 635 return true;
640 636
641 // FIXME: Might want to disable this check for caretBrowsing 637 // FIXME: Might want to disable this check for caretBrowsing
642 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli nquishesEditingFocus(oldFocusedElement)) 638 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli nquishesEditingFocus(oldFocusedElement))
643 return false; 639 return false;
644 640
645 m_page->chrome().client().willSetInputMethodState(); 641 m_page->chrome().client().willSetInputMethodState();
646 642
647 RefPtr<Document> newDocument; 643 RefPtr<Document> newDocument;
648 if (element) 644 if (element)
649 newDocument = &element->document(); 645 newDocument = &element->document();
650 else if (newFocusedFrame) 646 else if (newFocusedFrame)
651 newDocument = newFocusedFrame->document(); 647 newDocument = newFocusedFrame->document();
652 648
653 if (newDocument && oldDocument == newDocument && newDocument->focusedElement () == element) 649 if (newDocument && oldDocument == newDocument && newDocument->focusedElement () == element)
654 return true; 650 return true;
655 651
656 clearSelectionIfNeeded(oldFocusedFrame.get(), toLocalFrame(newFocusedFrame.g et()), element); 652 clearSelectionIfNeeded(oldFocusedFrame.get(), newFocusedFrame.get(), element );
657 653
658 if (oldDocument && oldDocument != newDocument) 654 if (oldDocument && oldDocument != newDocument)
659 oldDocument->setFocusedElement(nullptr); 655 oldDocument->setFocusedElement(nullptr);
660 656
661 if (newFocusedFrame && !newFocusedFrame->page()) { 657 if (newFocusedFrame && !newFocusedFrame->page()) {
662 setFocusedFrame(nullptr); 658 setFocusedFrame(nullptr);
663 return false; 659 return false;
664 } 660 }
665 setFocusedFrame(newFocusedFrame); 661 setFocusedFrame(newFocusedFrame);
666 662
(...skipping 11 matching lines...) Expand all
678 void FocusController::setActive(bool active) 674 void FocusController::setActive(bool active)
679 { 675 {
680 if (m_isActive == active) 676 if (m_isActive == active)
681 return; 677 return;
682 678
683 m_isActive = active; 679 m_isActive = active;
684 680
685 if (FrameView* view = m_page->mainFrame()->view()) 681 if (FrameView* view = m_page->mainFrame()->view())
686 view->updateControlTints(); 682 view->updateControlTints();
687 683
688 toLocalFrame(focusedOrMainFrame())->selection().pageActivationChanged(); 684 focusedOrMainFrame()->selection().pageActivationChanged();
689 } 685 }
690 686
691 static void contentAreaDidShowOrHide(ScrollableArea* scrollableArea, bool didSho w) 687 static void contentAreaDidShowOrHide(ScrollableArea* scrollableArea, bool didSho w)
692 { 688 {
693 if (didShow) 689 if (didShow)
694 scrollableArea->contentAreaDidShow(); 690 scrollableArea->contentAreaDidShow();
695 else 691 else
696 scrollableArea->contentAreaDidHide(); 692 scrollableArea->contentAreaDidHide();
697 } 693 }
698 694
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 // We found a new focus node, navigate to it. 865 // We found a new focus node, navigate to it.
870 Element* element = toElement(focusCandidate.focusableNode); 866 Element* element = toElement(focusCandidate.focusableNode);
871 ASSERT(element); 867 ASSERT(element);
872 868
873 element->focus(false, type); 869 element->focus(false, type);
874 return true; 870 return true;
875 } 871 }
876 872
877 bool FocusController::advanceFocusDirectionally(FocusType type) 873 bool FocusController::advanceFocusDirectionally(FocusType type)
878 { 874 {
879 // FIXME: Directional focus changes don't yet work with RemoteFrames. 875 LocalFrame* curFrame = focusedOrMainFrame();
880 if (!focusedOrMainFrame()->isLocalFrame())
881 return false;
882 LocalFrame* curFrame = toLocalFrame(focusedOrMainFrame());
883 ASSERT(curFrame); 876 ASSERT(curFrame);
884 877
885 Document* focusedDocument = curFrame->document(); 878 Document* focusedDocument = curFrame->document();
886 if (!focusedDocument) 879 if (!focusedDocument)
887 return false; 880 return false;
888 881
889 Element* focusedElement = focusedDocument->focusedElement(); 882 Element* focusedElement = focusedDocument->focusedElement();
890 Node* container = focusedDocument; 883 Node* container = focusedDocument;
891 884
892 if (container->isDocumentNode()) 885 if (container->isDocumentNode())
(...skipping 18 matching lines...) Expand all
911 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */); 904 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */);
912 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type, container); 905 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type, container);
913 if (container && container->isDocumentNode()) 906 if (container && container->isDocumentNode())
914 toDocument(container)->updateLayoutIgnorePendingStylesheets(); 907 toDocument(container)->updateLayoutIgnorePendingStylesheets();
915 } while (!consumed && container); 908 } while (!consumed && container);
916 909
917 return consumed; 910 return consumed;
918 } 911 }
919 912
920 } // namespace WebCore 913 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/page/FocusController.h ('k') | Source/core/page/PageSerializer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698