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

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

Issue 189573002: Convert HTMLFrameOwnerElement and FocusController to use Frame. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added alias for LocalFrame downcast Created 6 years, 9 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) 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 (LocalFrame* frame = root->document().frame()) 90 if (Frame* 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<LocalFrame> frame) 234 void FocusController::setFocusedFrame(PassRefPtr<Frame> 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; 242 RefPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFram e()) ? toLocalFrame(m_focusedFrame.get()) : 0;
eseidel 2014/03/27 19:56:41 Sometimes we really want a version of these "to" f
243 RefPtr<LocalFrame> newFrame = frame; 243 RefPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFram e(frame.get()) : 0;
244 244
245 m_focusedFrame = newFrame; 245 m_focusedFrame = frame.get();
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 LocalFrame* FocusController::focusedOrMainFrame() const 263 Frame* FocusController::focusedOrMainFrame() const
264 { 264 {
265 if (LocalFrame* frame = focusedFrame()) 265 if (Frame* 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) 277 if (!m_isFocused && focusedOrMainFrame()->isLocalFrame())
278 focusedOrMainFrame()->eventHandler().stopAutoscroll(); 278 toLocalFrame(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->view()) { 285 if (m_focusedFrame && m_focusedFrame->isLocalFrame() && toLocalFrame(m_focus edFrame.get())->view()) {
286 m_focusedFrame->selection().setFocused(focused); 286 toLocalFrame(m_focusedFrame.get())->selection().setFocused(focused);
287 dispatchEventsOnWindowAndFocusedNode(m_focusedFrame->document(), focused ); 287 dispatchEventsOnWindowAndFocusedNode(toLocalFrame(m_focusedFrame.get())- >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 LocalFrame* frame = focusedOrMainFrame(); 342 // FIXME: Focus advancement won't work with externally rendered frames until after
343 // inter-frame focus control is moved out of Blink.
344 if (!focusedOrMainFrame()->isLocalFrame())
345 return false;
346 LocalFrame* frame = toLocalFrame(focusedOrMainFrame());
343 ASSERT(frame); 347 ASSERT(frame);
344 Document* document = frame->document(); 348 Document* document = frame->document();
345 349
346 Node* currentNode = document->focusedElement(); 350 Node* currentNode = document->focusedElement();
347 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself 351 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself
348 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn abled(); 352 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn abled();
349 353
350 if (caretBrowsing && !currentNode) 354 if (caretBrowsing && !currentNode)
351 currentNode = frame->selection().start().deprecatedNode(); 355 currentNode = frame->selection().start().deprecatedNode();
352 356
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 if (Node* shadowAncestorNode = root->deprecatedShadowAncestorNode()) { 622 if (Node* shadowAncestorNode = root->deprecatedShadowAncestorNode()) {
619 if (!shadowAncestorNode->hasTagName(inputTag) && !shadowAncestor Node->hasTagName(textareaTag)) 623 if (!shadowAncestorNode->hasTagName(inputTag) && !shadowAncestor Node->hasTagName(textareaTag))
620 return; 624 return;
621 } 625 }
622 } 626 }
623 } 627 }
624 628
625 selection.clear(); 629 selection.clear();
626 } 630 }
627 631
628 bool FocusController::setFocusedElement(Element* element, PassRefPtr<LocalFrame> newFocusedFrame, FocusType type) 632 bool FocusController::setFocusedElement(Element* element, PassRefPtr<Frame> newF ocusedFrame, FocusType type)
629 { 633 {
630 RefPtr<LocalFrame> oldFocusedFrame = focusedFrame(); 634 RefPtr<LocalFrame> oldFocusedFrame = toLocalFrame(focusedFrame());
631 RefPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : 0; 635 RefPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : 0;
632 636
633 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : 0 ; 637 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : 0 ;
634 if (element && oldFocusedElement == element) 638 if (element && oldFocusedElement == element)
635 return true; 639 return true;
636 640
637 // FIXME: Might want to disable this check for caretBrowsing 641 // FIXME: Might want to disable this check for caretBrowsing
638 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli nquishesEditingFocus(oldFocusedElement)) 642 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli nquishesEditingFocus(oldFocusedElement))
639 return false; 643 return false;
640 644
641 m_page->chrome().client().willSetInputMethodState(); 645 m_page->chrome().client().willSetInputMethodState();
642 646
643 RefPtr<Document> newDocument; 647 RefPtr<Document> newDocument;
644 if (element) 648 if (element)
645 newDocument = &element->document(); 649 newDocument = &element->document();
646 else if (newFocusedFrame) 650 else if (newFocusedFrame)
647 newDocument = newFocusedFrame->document(); 651 newDocument = newFocusedFrame->document();
648 652
649 if (newDocument && oldDocument == newDocument && newDocument->focusedElement () == element) 653 if (newDocument && oldDocument == newDocument && newDocument->focusedElement () == element)
650 return true; 654 return true;
651 655
652 clearSelectionIfNeeded(oldFocusedFrame.get(), newFocusedFrame.get(), element ); 656 clearSelectionIfNeeded(oldFocusedFrame.get(), toLocalFrame(newFocusedFrame.g et()), element);
653 657
654 if (oldDocument && oldDocument != newDocument) 658 if (oldDocument && oldDocument != newDocument)
655 oldDocument->setFocusedElement(nullptr); 659 oldDocument->setFocusedElement(nullptr);
656 660
657 if (newFocusedFrame && !newFocusedFrame->page()) { 661 if (newFocusedFrame && !newFocusedFrame->page()) {
658 setFocusedFrame(nullptr); 662 setFocusedFrame(nullptr);
659 return false; 663 return false;
660 } 664 }
661 setFocusedFrame(newFocusedFrame); 665 setFocusedFrame(newFocusedFrame);
662 666
(...skipping 11 matching lines...) Expand all
674 void FocusController::setActive(bool active) 678 void FocusController::setActive(bool active)
675 { 679 {
676 if (m_isActive == active) 680 if (m_isActive == active)
677 return; 681 return;
678 682
679 m_isActive = active; 683 m_isActive = active;
680 684
681 if (FrameView* view = m_page->mainFrame()->view()) 685 if (FrameView* view = m_page->mainFrame()->view())
682 view->updateControlTints(); 686 view->updateControlTints();
683 687
684 focusedOrMainFrame()->selection().pageActivationChanged(); 688 toLocalFrame(focusedOrMainFrame())->selection().pageActivationChanged();
685 } 689 }
686 690
687 static void contentAreaDidShowOrHide(ScrollableArea* scrollableArea, bool didSho w) 691 static void contentAreaDidShowOrHide(ScrollableArea* scrollableArea, bool didSho w)
688 { 692 {
689 if (didShow) 693 if (didShow)
690 scrollableArea->contentAreaDidShow(); 694 scrollableArea->contentAreaDidShow();
691 else 695 else
692 scrollableArea->contentAreaDidHide(); 696 scrollableArea->contentAreaDidHide();
693 } 697 }
694 698
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 // We found a new focus node, navigate to it. 869 // We found a new focus node, navigate to it.
866 Element* element = toElement(focusCandidate.focusableNode); 870 Element* element = toElement(focusCandidate.focusableNode);
867 ASSERT(element); 871 ASSERT(element);
868 872
869 element->focus(false, type); 873 element->focus(false, type);
870 return true; 874 return true;
871 } 875 }
872 876
873 bool FocusController::advanceFocusDirectionally(FocusType type) 877 bool FocusController::advanceFocusDirectionally(FocusType type)
874 { 878 {
875 LocalFrame* curFrame = focusedOrMainFrame(); 879 // FIXME: Directional focus changes don't yet work with RemoteFrames.
880 if (!focusedOrMainFrame()->isLocalFrame())
881 return false;
882 LocalFrame* curFrame = toLocalFrame(focusedOrMainFrame());
876 ASSERT(curFrame); 883 ASSERT(curFrame);
877 884
878 Document* focusedDocument = curFrame->document(); 885 Document* focusedDocument = curFrame->document();
879 if (!focusedDocument) 886 if (!focusedDocument)
880 return false; 887 return false;
881 888
882 Element* focusedElement = focusedDocument->focusedElement(); 889 Element* focusedElement = focusedDocument->focusedElement();
883 Node* container = focusedDocument; 890 Node* container = focusedDocument;
884 891
885 if (container->isDocumentNode()) 892 if (container->isDocumentNode())
(...skipping 18 matching lines...) Expand all
904 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */); 911 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */);
905 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type, container); 912 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type, container);
906 if (container && container->isDocumentNode()) 913 if (container && container->isDocumentNode())
907 toDocument(container)->updateLayoutIgnorePendingStylesheets(); 914 toDocument(container)->updateLayoutIgnorePendingStylesheets();
908 } while (!consumed && container); 915 } while (!consumed && container);
909 916
910 return consumed; 917 return consumed;
911 } 918 }
912 919
913 } // namespace WebCore 920 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698