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

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

Issue 517043003: Move Frame to the Oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Back out non-Oilpan experiment + tidy up by adding frame() ref accessors Created 6 years, 3 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 22 matching lines...) Expand all
33 #include "core/dom/Element.h" 33 #include "core/dom/Element.h"
34 #include "core/dom/ElementTraversal.h" 34 #include "core/dom/ElementTraversal.h"
35 #include "core/dom/NodeTraversal.h" 35 #include "core/dom/NodeTraversal.h"
36 #include "core/dom/Range.h" 36 #include "core/dom/Range.h"
37 #include "core/dom/shadow/ElementShadow.h" 37 #include "core/dom/shadow/ElementShadow.h"
38 #include "core/dom/shadow/ShadowRoot.h" 38 #include "core/dom/shadow/ShadowRoot.h"
39 #include "core/editing/Editor.h" 39 #include "core/editing/Editor.h"
40 #include "core/editing/FrameSelection.h" 40 #include "core/editing/FrameSelection.h"
41 #include "core/editing/htmlediting.h" // For firstPositionInOrBeforeNode 41 #include "core/editing/htmlediting.h" // For firstPositionInOrBeforeNode
42 #include "core/events/Event.h" 42 #include "core/events/Event.h"
43 #include "core/frame/FrameView.h"
43 #include "core/frame/LocalDOMWindow.h" 44 #include "core/frame/LocalDOMWindow.h"
44 #include "core/frame/FrameView.h"
45 #include "core/frame/LocalFrame.h" 45 #include "core/frame/LocalFrame.h"
46 #include "core/html/HTMLAreaElement.h" 46 #include "core/html/HTMLAreaElement.h"
47 #include "core/html/HTMLImageElement.h" 47 #include "core/html/HTMLImageElement.h"
48 #include "core/html/HTMLPlugInElement.h" 48 #include "core/html/HTMLPlugInElement.h"
49 #include "core/html/HTMLShadowElement.h" 49 #include "core/html/HTMLShadowElement.h"
50 #include "core/html/HTMLTextFormControlElement.h" 50 #include "core/html/HTMLTextFormControlElement.h"
51 #include "core/page/Chrome.h" 51 #include "core/page/Chrome.h"
52 #include "core/page/ChromeClient.h" 52 #include "core/page/ChromeClient.h"
53 #include "core/page/EventHandler.h" 53 #include "core/page/EventHandler.h"
54 #include "core/page/FrameTree.h" 54 #include "core/page/FrameTree.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 222 }
223 223
224 FocusController::FocusController(Page* page) 224 FocusController::FocusController(Page* page)
225 : m_page(page) 225 : m_page(page)
226 , m_isActive(false) 226 , m_isActive(false)
227 , m_isFocused(false) 227 , m_isFocused(false)
228 , m_isChangingFocusedFrame(false) 228 , m_isChangingFocusedFrame(false)
229 { 229 {
230 } 230 }
231 231
232 PassOwnPtr<FocusController> FocusController::create(Page* page) 232 PassOwnPtrWillBeRawPtr<FocusController> FocusController::create(Page* page)
233 { 233 {
234 return adoptPtr(new FocusController(page)); 234 return adoptPtrWillBeNoop(new FocusController(page));
235 } 235 }
236 236
237 void FocusController::setFocusedFrame(PassRefPtr<Frame> frame) 237 void FocusController::setFocusedFrame(PassRefPtrWillBeRawPtr<Frame> frame)
238 { 238 {
239 ASSERT(!frame || frame->page() == m_page); 239 ASSERT(!frame || frame->page() == m_page);
240 if (m_focusedFrame == frame || m_isChangingFocusedFrame) 240 if (m_focusedFrame == frame || m_isChangingFocusedFrame)
241 return; 241 return;
242 242
243 m_isChangingFocusedFrame = true; 243 m_isChangingFocusedFrame = true;
244 244
245 RefPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFram e()) ? toLocalFrame(m_focusedFrame.get()) : 0; 245 RefPtrWillBeRawPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame- >isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : 0;
246 RefPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFram e(frame.get()) : 0; 246
247 RefPtrWillBeRawPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : 0;
247 248
248 m_focusedFrame = frame.get(); 249 m_focusedFrame = frame.get();
249 250
250 // Now that the frame is updated, fire events and update the selection focus ed states of both frames. 251 // Now that the frame is updated, fire events and update the selection focus ed states of both frames.
251 if (oldFrame && oldFrame->view()) { 252 if (oldFrame && oldFrame->view()) {
252 oldFrame->selection().setFocused(false); 253 oldFrame->selection().setFocused(false);
253 oldFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::blur) ); 254 oldFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::blur) );
254 } 255 }
255 256
256 if (newFrame && newFrame->view() && isFocused()) { 257 if (newFrame && newFrame->view() && isFocused()) {
257 newFrame->selection().setFocused(true); 258 newFrame->selection().setFocused(true);
258 newFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::focus )); 259 newFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::focus ));
259 } 260 }
260 261
261 m_isChangingFocusedFrame = false; 262 m_isChangingFocusedFrame = false;
262 263
263 m_page->chrome().client().focusedFrameChanged(newFrame.get()); 264 m_page->chrome().client().focusedFrameChanged(newFrame.get());
264 } 265 }
265 266
266 void FocusController::focusDocumentView(PassRefPtr<Frame> frame) 267 void FocusController::focusDocumentView(PassRefPtrWillBeRawPtr<Frame> frame)
267 { 268 {
268 ASSERT(!frame || frame->page() == m_page); 269 ASSERT(!frame || frame->page() == m_page);
269 if (m_focusedFrame == frame) 270 if (m_focusedFrame == frame)
270 return; 271 return;
271 272
272 RefPtr<LocalFrame> focusedFrame = (m_focusedFrame && m_focusedFrame->isLocal Frame()) ? toLocalFrame(m_focusedFrame.get()) : 0; 273 RefPtrWillBeRawPtr<LocalFrame> focusedFrame = (m_focusedFrame && m_focusedFr ame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : 0;
273 if (focusedFrame && focusedFrame->view()) { 274 if (focusedFrame && focusedFrame->view()) {
274 RefPtrWillBeRawPtr<Document> document = focusedFrame->document(); 275 RefPtrWillBeRawPtr<Document> document = focusedFrame->document();
275 Element* focusedElement = document ? document->focusedElement() : 0; 276 Element* focusedElement = document ? document->focusedElement() : 0;
276 if (focusedElement) { 277 if (focusedElement) {
277 focusedElement->dispatchBlurEvent(0); 278 focusedElement->dispatchBlurEvent(0);
278 if (focusedElement == document->focusedElement()) { 279 if (focusedElement == document->focusedElement()) {
279 focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, 0); 280 focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, 0);
280 if (focusedElement == document->focusedElement()) 281 if (focusedElement == document->focusedElement())
281 focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFoc usOut, 0); 282 focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFoc usOut, 0);
282 } 283 }
283 } 284 }
284 } 285 }
285 286
286 RefPtr<LocalFrame> newFocusedFrame = (frame && frame->isLocalFrame()) ? toLo calFrame(frame.get()) : 0; 287 RefPtrWillBeRawPtr<LocalFrame> newFocusedFrame = (frame && frame->isLocalFra me()) ? toLocalFrame(frame.get()) : 0;
287 if (newFocusedFrame && newFocusedFrame->view()) { 288 if (newFocusedFrame && newFocusedFrame->view()) {
288 RefPtrWillBeRawPtr<Document> document = newFocusedFrame->document(); 289 RefPtrWillBeRawPtr<Document> document = newFocusedFrame->document();
289 Element* focusedElement = document ? document->focusedElement() : 0; 290 Element* focusedElement = document ? document->focusedElement() : 0;
290 if (focusedElement) { 291 if (focusedElement) {
291 focusedElement->dispatchFocusEvent(0, FocusTypePage); 292 focusedElement->dispatchFocusEvent(0, FocusTypePage);
292 if (focusedElement == document->focusedElement()) { 293 if (focusedElement == document->focusedElement()) {
293 document->focusedElement()->dispatchFocusInEvent(EventTypeNames: :focusin, 0, FocusTypePage); 294 document->focusedElement()->dispatchFocusInEvent(EventTypeNames: :focusin, 0, FocusTypePage);
294 if (focusedElement == document->focusedElement()) 295 if (focusedElement == document->focusedElement())
295 document->focusedElement()->dispatchFocusInEvent(EventTypeNa mes::DOMFocusIn, 0, FocusTypePage); 296 document->focusedElement()->dispatchFocusInEvent(EventTypeNa mes::DOMFocusIn, 0, FocusTypePage);
296 } 297 }
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 667
667 if (!enclosingTextFormControl(selectionStartNode)) 668 if (!enclosingTextFormControl(selectionStartNode))
668 return; 669 return;
669 670
670 if (selectionStartNode->isInShadowTree() && selectionStartNode->shadowHost() == newFocusedNode) 671 if (selectionStartNode->isInShadowTree() && selectionStartNode->shadowHost() == newFocusedNode)
671 return; 672 return;
672 673
673 selection.clear(); 674 selection.clear();
674 } 675 }
675 676
676 bool FocusController::setFocusedElement(Element* element, PassRefPtr<Frame> newF ocusedFrame, FocusType type) 677 bool FocusController::setFocusedElement(Element* element, PassRefPtrWillBeRawPtr <Frame> newFocusedFrame, FocusType type)
677 { 678 {
678 RefPtr<LocalFrame> oldFocusedFrame = toLocalFrame(focusedFrame()); 679 RefPtrWillBeRawPtr<LocalFrame> oldFocusedFrame = toLocalFrame(focusedFrame() );
679 RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame ->document() : 0; 680 RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame ->document() : 0;
680 681
681 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : 0 ; 682 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : 0 ;
682 if (element && oldFocusedElement == element) 683 if (element && oldFocusedElement == element)
683 return true; 684 return true;
684 685
685 // FIXME: Might want to disable this check for caretBrowsing 686 // FIXME: Might want to disable this check for caretBrowsing
686 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli nquishesEditingFocus(oldFocusedElement)) 687 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli nquishesEditingFocus(oldFocusedElement))
687 return false; 688 return false;
688 689
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 consumed = advanceFocusDirectionallyInContainer(container, startingRect, type); 918 consumed = advanceFocusDirectionallyInContainer(container, startingRect, type);
918 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */); 919 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */);
919 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type, container); 920 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type, container);
920 if (container && container->isDocumentNode()) 921 if (container && container->isDocumentNode())
921 toDocument(container)->updateLayoutIgnorePendingStylesheets(); 922 toDocument(container)->updateLayoutIgnorePendingStylesheets();
922 } while (!consumed && container); 923 } while (!consumed && container);
923 924
924 return consumed; 925 return consumed;
925 } 926 }
926 927
928 void FocusController::trace(Visitor* visitor)
929 {
930 visitor->trace(m_page);
931 visitor->trace(m_focusedFrame);
932 }
933
927 } // namespace blink 934 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698