Commit fede3e50 authored by weinig@apple.com's avatar weinig@apple.com

Chrome, DragController and FocusController should hold onto a Page&

https://bugs.webkit.org/show_bug.cgi?id=121325

Reviewed by Anders Carlsson.

* editing/FrameSelection.cpp:
* editing/FrameSelection.h:
* page/Chrome.cpp:
(WebCore::Chrome::Chrome):
(WebCore::Chrome::scroll):
(WebCore::Chrome::createWindow):
(WebCore::canRunModalIfDuringPageDismissal):
(WebCore::Chrome::runBeforeUnloadConfirmPanel):
(WebCore::Chrome::runJavaScriptAlert):
(WebCore::Chrome::runJavaScriptConfirm):
(WebCore::Chrome::runJavaScriptPrompt):
(WebCore::Chrome::mouseDidMoveOverElement):
(WebCore::Chrome::setToolTip):
(WebCore::Chrome::windowScreenDidChange):
* page/Chrome.h:
* page/DragController.cpp:
* page/DragController.h:
* page/mac/DragControllerMac.mm:
* page/FocusController.cpp:
* page/FocusController.h:
* page/Page.cpp:
(WebCore::Page::Page):
* page/PageGroupLoadDeferrer.cpp:
* page/PageGroupLoadDeferrer.h:
Take references where possible.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@155731 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 018818de
2013-09-13 Sam Weinig <sam@webkit.org>
Chrome, DragController and FocusController should hold onto a Page&
https://bugs.webkit.org/show_bug.cgi?id=121325
Reviewed by Anders Carlsson.
* editing/FrameSelection.cpp:
* editing/FrameSelection.h:
* page/Chrome.cpp:
(WebCore::Chrome::Chrome):
(WebCore::Chrome::scroll):
(WebCore::Chrome::createWindow):
(WebCore::canRunModalIfDuringPageDismissal):
(WebCore::Chrome::runBeforeUnloadConfirmPanel):
(WebCore::Chrome::runJavaScriptAlert):
(WebCore::Chrome::runJavaScriptConfirm):
(WebCore::Chrome::runJavaScriptPrompt):
(WebCore::Chrome::mouseDidMoveOverElement):
(WebCore::Chrome::setToolTip):
(WebCore::Chrome::windowScreenDidChange):
* page/Chrome.h:
* page/DragController.cpp:
* page/DragController.h:
* page/mac/DragControllerMac.mm:
* page/FocusController.cpp:
* page/FocusController.h:
* page/Page.cpp:
(WebCore::Page::Page):
* page/PageGroupLoadDeferrer.cpp:
* page/PageGroupLoadDeferrer.h:
Take references where possible.
2013-09-13 Anders Carlsson <andersca@apple.com>
Use nullptr instead of 0 in calls to HashMap::add
......@@ -89,11 +89,6 @@ DragCaretController::DragCaretController()
{
}
PassOwnPtr<DragCaretController> DragCaretController::create()
{
return adoptPtr(new DragCaretController);
}
bool DragCaretController::isContentRichlyEditable() const
{
return isRichlyEditablePosition(m_position.deepEquivalent());
......
......@@ -87,7 +87,7 @@ class DragCaretController : private CaretBase {
WTF_MAKE_NONCOPYABLE(DragCaretController);
WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<DragCaretController> create();
DragCaretController();
RenderObject* caretRenderer() const;
void paintDragCaret(Frame*, GraphicsContext*, const LayoutPoint&, const LayoutRect& clipRect) const;
......@@ -103,8 +103,6 @@ public:
void nodeWillBeRemoved(Node*);
private:
DragCaretController();
VisiblePosition m_position;
};
......
......@@ -62,12 +62,11 @@ namespace WebCore {
using namespace HTMLNames;
using namespace std;
Chrome::Chrome(Page* page, ChromeClient* client)
Chrome::Chrome(Page& page, ChromeClient& client)
: m_page(page)
, m_client(*client)
, m_client(client)
, m_displayID(0)
{
ASSERT(client);
}
Chrome::~Chrome()
......@@ -75,11 +74,6 @@ Chrome::~Chrome()
m_client.chromeDestroyed();
}
PassOwnPtr<Chrome> Chrome::create(Page* page, ChromeClient* client)
{
return adoptPtr(new Chrome(page, client));
}
void Chrome::invalidateRootView(const IntRect& updateRect, bool immediate)
{
m_client.invalidateRootView(updateRect, immediate);
......@@ -98,7 +92,7 @@ void Chrome::invalidateContentsForSlowScroll(const IntRect& updateRect, bool imm
void Chrome::scroll(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect)
{
m_client.scroll(scrollDelta, rectToScroll, clipRect);
InspectorInstrumentation::didScroll(m_page);
InspectorInstrumentation::didScroll(&m_page);
}
#if USE(TILED_BACKING_STORE)
......@@ -194,7 +188,7 @@ Page* Chrome::createWindow(Frame* frame, const FrameLoadRequest& request, const
if (!newPage)
return 0;
if (StorageNamespace* oldSessionStorage = m_page->sessionStorage(false))
if (StorageNamespace* oldSessionStorage = m_page.sessionStorage(false))
newPage->setSessionStorage(oldSessionStorage->copy(newPage));
return newPage;
......@@ -210,12 +204,12 @@ bool Chrome::canRunModal() const
return m_client.canRunModal();
}
static bool canRunModalIfDuringPageDismissal(Page* page, ChromeClient::DialogType dialog, const String& message)
static bool canRunModalIfDuringPageDismissal(Page& page, ChromeClient::DialogType dialog, const String& message)
{
for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
for (Frame* frame = &page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
FrameLoader::PageDismissalType dismissal = frame->loader().pageDismissalEventBeingDispatched();
if (dismissal != FrameLoader::NoDismissal)
return page->chrome().client().shouldRunModalDialogDuringPageDismissal(dialog, message, dismissal);
return page.chrome().client().shouldRunModalDialogDuringPageDismissal(dialog, message, dismissal);
}
return true;
}
......@@ -294,7 +288,7 @@ bool Chrome::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
// otherwise cause the load to continue while we're in the middle of executing JavaScript.
PageGroupLoadDeferrer deferrer(m_page, true);
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(m_page, message);
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(&m_page, message);
bool ok = m_client.runBeforeUnloadConfirmPanel(message, frame);
InspectorInstrumentation::didRunJavaScriptDialog(cookie);
return ok;
......@@ -318,7 +312,7 @@ void Chrome::runJavaScriptAlert(Frame* frame, const String& message)
notifyPopupOpeningObservers();
String displayMessage = frame->displayStringModifiedByEncoding(message);
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(m_page, displayMessage);
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(&m_page, displayMessage);
m_client.runJavaScriptAlert(frame, displayMessage);
InspectorInstrumentation::didRunJavaScriptDialog(cookie);
}
......@@ -336,7 +330,7 @@ bool Chrome::runJavaScriptConfirm(Frame* frame, const String& message)
notifyPopupOpeningObservers();
String displayMessage = frame->displayStringModifiedByEncoding(message);
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(m_page, displayMessage);
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(&m_page, displayMessage);
bool ok = m_client.runJavaScriptConfirm(frame, displayMessage);
InspectorInstrumentation::didRunJavaScriptDialog(cookie);
return ok;
......@@ -355,7 +349,7 @@ bool Chrome::runJavaScriptPrompt(Frame* frame, const String& prompt, const Strin
notifyPopupOpeningObservers();
String displayPrompt = frame->displayStringModifiedByEncoding(prompt);
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(m_page, displayPrompt);
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(&m_page, displayPrompt);
bool ok = m_client.runJavaScriptPrompt(frame, displayPrompt, frame->displayStringModifiedByEncoding(defaultValue), result);
InspectorInstrumentation::didRunJavaScriptDialog(cookie);
......@@ -391,7 +385,7 @@ void Chrome::mouseDidMoveOverElement(const HitTestResult& result, unsigned modif
prefetchDNS(result.absoluteLinkURL().host());
m_client.mouseDidMoveOverElement(result, modifierFlags);
InspectorInstrumentation::mouseDidMoveOverElement(m_page, result, modifierFlags);
InspectorInstrumentation::mouseDidMoveOverElement(&m_page, result, modifierFlags);
}
void Chrome::setToolTip(const HitTestResult& result)
......@@ -401,7 +395,7 @@ void Chrome::setToolTip(const HitTestResult& result)
String toolTip = result.spellingToolTip(toolTipDirection);
// Next priority is a toolTip from a URL beneath the mouse (if preference is set to show those).
if (toolTip.isEmpty() && m_page->settings().showsURLsInToolTips()) {
if (toolTip.isEmpty() && m_page.settings().showsURLsInToolTips()) {
if (Element* element = result.innerNonSharedElement()) {
// Get tooltip representing form action, if relevant
if (isHTMLInputElement(element)) {
......@@ -431,7 +425,7 @@ void Chrome::setToolTip(const HitTestResult& result)
if (toolTip.isEmpty())
toolTip = result.title(toolTipDirection);
if (toolTip.isEmpty() && m_page->settings().showsToolTipOverTruncatedText())
if (toolTip.isEmpty() && m_page.settings().showsToolTipOverTruncatedText())
toolTip = result.innerTextIfTruncated(toolTipDirection);
// Lastly, for <input type="file"> that allow multiple files, we'll consider a tooltip for the selected filenames
......@@ -539,7 +533,7 @@ void Chrome::windowScreenDidChange(PlatformDisplayID displayID)
m_displayID = displayID;
for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
if (frame->document())
frame->document()->windowScreenDidChange(displayID);
}
......
......@@ -63,10 +63,9 @@ struct WindowFeatures;
class Chrome : public HostWindow {
public:
Chrome(Page&, ChromeClient&);
~Chrome();
static PassOwnPtr<Chrome> create(Page*, ChromeClient*);
ChromeClient& client() { return m_client; }
// HostWindow methods.
......@@ -184,10 +183,9 @@ public:
void unregisterPopupOpeningObserver(PopupOpeningObserver*);
private:
Chrome(Page*, ChromeClient*);
void notifyPopupOpeningObservers() const;
Page* m_page;
Page& m_page;
ChromeClient& m_client;
PlatformDisplayID m_displayID;
Vector<PopupOpeningObserver*> m_popupOpeningObservers;
......
This diff is collapsed.
......@@ -51,11 +51,12 @@ namespace WebCore {
class DragController {
WTF_MAKE_NONCOPYABLE(DragController); WTF_MAKE_FAST_ALLOCATED;
public:
DragController(Page&, DragClient&);
~DragController();
static PassOwnPtr<DragController> create(Page*, DragClient*);
DragClient* client() const { return m_client; }
DragClient& client() const { return m_client; }
DragSession dragEntered(DragData*);
void dragExited(DragData*);
......@@ -91,8 +92,6 @@ namespace WebCore {
static const float DragImageAlpha;
private:
DragController(Page*, DragClient*);
bool dispatchTextInputEventFor(Frame*, DragData*);
bool canProcessDrag(DragData*);
bool concludeEditDrag(DragData*);
......@@ -112,8 +111,8 @@ namespace WebCore {
void cleanupAfterSystemDrag();
void declareAndWriteDragImage(Clipboard*, Element*, const KURL&, const String& label);
Page* m_page;
DragClient* m_client;
Page& m_page;
DragClient& m_client;
RefPtr<Document> m_documentUnderMouse; // The document the mouse was last dragged over.
RefPtr<Document> m_dragInitiator; // The Document (if any) that initiated the drag.
......
......@@ -162,7 +162,7 @@ static inline bool shouldVisit(Element* element, KeyboardEvent* event)
return element->isKeyboardFocusable(event) || isNonFocusableShadowHost(element, event);
}
FocusController::FocusController(Page* page)
FocusController::FocusController(Page& page)
: m_page(page)
, m_isActive(false)
, m_isFocused(false)
......@@ -171,14 +171,9 @@ FocusController::FocusController(Page* page)
{
}
PassOwnPtr<FocusController> FocusController::create(Page* page)
{
return adoptPtr(new FocusController(page));
}
void FocusController::setFocusedFrame(PassRefPtr<Frame> frame)
{
ASSERT(!frame || frame->page() == m_page);
ASSERT(!frame || frame->page() == &m_page);
if (m_focusedFrame == frame || m_isChangingFocusedFrame)
return;
......@@ -200,7 +195,7 @@ void FocusController::setFocusedFrame(PassRefPtr<Frame> frame)
newFrame->document()->dispatchWindowEvent(Event::create(eventNames().focusEvent, false, false));
}
m_page->chrome().focusedFrameChanged(newFrame.get());
m_page.chrome().focusedFrameChanged(newFrame.get());
m_isChangingFocusedFrame = false;
}
......@@ -209,7 +204,7 @@ Frame& FocusController::focusedOrMainFrame() const
{
if (Frame* frame = focusedFrame())
return *frame;
return m_page->mainFrame();
return m_page.mainFrame();
}
void FocusController::setFocused(bool focused)
......@@ -223,7 +218,7 @@ void FocusController::setFocused(bool focused)
focusedOrMainFrame().eventHandler().stopAutoscrollTimer();
if (!m_focusedFrame)
setFocusedFrame(&m_page->mainFrame());
setFocusedFrame(&m_page.mainFrame());
if (m_focusedFrame->view()) {
m_focusedFrame->selection().setFocused(focused);
......@@ -298,15 +293,15 @@ bool FocusController::advanceFocusInDocumentOrder(FocusDirection direction, Keyb
if (!element) {
// We didn't find a node to focus, so we should try to pass focus to Chrome.
if (!initialFocus && m_page->chrome().canTakeFocus(direction)) {
if (!initialFocus && m_page.chrome().canTakeFocus(direction)) {
document->setFocusedElement(0);
setFocusedFrame(0);
m_page->chrome().takeFocus(direction);
m_page.chrome().takeFocus(direction);
return true;
}
// Chrome doesn't want focus, so we should wrap focus.
element = findFocusableElementRecursively(direction, FocusNavigationScope::focusNavigationScopeOf(m_page->mainFrame().document()), 0, event);
element = findFocusableElementRecursively(direction, FocusNavigationScope::focusNavigationScopeOf(m_page.mainFrame().document()), 0, event);
element = findFocusableElementDescendingDownIntoFrameDocument(direction, element.get(), event);
if (!element)
......@@ -605,21 +600,21 @@ bool FocusController::setFocusedElement(Element* element, PassRefPtr<Frame> newF
if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !relinquishesEditingFocus(oldFocusedElement))
return false;
m_page->editorClient()->willSetInputMethodState();
m_page.editorClient()->willSetInputMethodState();
clearSelectionIfNeeded(oldFocusedFrame.get(), newFocusedFrame.get(), element);
if (!element) {
if (oldDocument)
oldDocument->setFocusedElement(0);
m_page->editorClient()->setInputMethodState(false);
m_page.editorClient()->setInputMethodState(false);
return true;
}
RefPtr<Document> newDocument = &element->document();
if (newDocument->focusedElement() == element) {
m_page->editorClient()->setInputMethodState(element->shouldUseInputMethod());
m_page.editorClient()->setInputMethodState(element->shouldUseInputMethod());
return true;
}
......@@ -640,7 +635,7 @@ bool FocusController::setFocusedElement(Element* element, PassRefPtr<Frame> newF
}
if (newDocument->focusedElement() == element)
m_page->editorClient()->setInputMethodState(element->shouldUseInputMethod());
m_page.editorClient()->setInputMethodState(element->shouldUseInputMethod());
return true;
}
......@@ -652,7 +647,7 @@ void FocusController::setActive(bool active)
m_isActive = active;
if (FrameView* view = m_page->mainFrame().view()) {
if (FrameView* view = m_page.mainFrame().view()) {
if (!view->platformWidget()) {
view->updateLayoutAndStyleIfNeededRecursive();
view->updateControlTints();
......@@ -680,13 +675,13 @@ void FocusController::setContainingWindowIsVisible(bool containingWindowIsVisibl
m_containingWindowIsVisible = containingWindowIsVisible;
FrameView* view = m_page->mainFrame().view();
FrameView* view = m_page.mainFrame().view();
if (!view)
return;
contentAreaDidShowOrHide(view, containingWindowIsVisible);
for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
FrameView* frameView = frame->view();
if (!frameView)
continue;
......@@ -697,7 +692,7 @@ void FocusController::setContainingWindowIsVisible(bool containingWindowIsVisibl
for (HashSet<ScrollableArea*>::const_iterator it = scrollableAreas->begin(), end = scrollableAreas->end(); it != end; ++it) {
ScrollableArea* scrollableArea = *it;
ASSERT(scrollableArea->scrollbarsCanBeActive() || m_page->shouldSuppressScrollbarAnimations());
ASSERT(scrollableArea->scrollbarsCanBeActive() || m_page.shouldSuppressScrollbarAnimations());
contentAreaDidShowOrHide(scrollableArea, containingWindowIsVisible);
}
......
......@@ -62,7 +62,7 @@ private:
class FocusController {
WTF_MAKE_NONCOPYABLE(FocusController); WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<FocusController> create(Page*);
explicit FocusController(Page&);
void setFocusedFrame(PassRefPtr<Frame>);
Frame* focusedFrame() const { return m_focusedFrame.get(); }
......@@ -83,8 +83,6 @@ public:
bool containingWindowIsVisible() const { return m_containingWindowIsVisible; }
private:
explicit FocusController(Page*);
bool advanceFocusDirectionally(FocusDirection, KeyboardEvent*);
bool advanceFocusInDocumentOrder(FocusDirection, KeyboardEvent*, bool initialFocus);
......@@ -111,7 +109,7 @@ private:
bool advanceFocusDirectionallyInContainer(Node* container, const LayoutRect& startingRect, FocusDirection, KeyboardEvent*);
void findFocusCandidateInContainer(Node* container, const LayoutRect& startingRect, FocusDirection, KeyboardEvent*, FocusCandidate& closest);
Page* m_page;
Page& m_page;
RefPtr<Frame> m_focusedFrame;
bool m_isActive;
bool m_isFocused;
......
......@@ -124,12 +124,12 @@ float deviceScaleFactor(Frame* frame)
}
Page::Page(PageClients& pageClients)
: m_chrome(Chrome::create(this, pageClients.chromeClient))
, m_dragCaretController(DragCaretController::create())
: m_chrome(createOwned<Chrome>(*this, *pageClients.chromeClient))
, m_dragCaretController(createOwned<DragCaretController>())
#if ENABLE(DRAG_SUPPORT)
, m_dragController(DragController::create(this, pageClients.dragClient))
, m_dragController(createOwned<DragController>(*this, *pageClients.dragClient))
#endif
, m_focusController(FocusController::create(this))
, m_focusController(createOwned<FocusController>(*this))
#if ENABLE(CONTEXT_MENUS)
, m_contextMenuController(createOwned<ContextMenuController>(*this, *pageClients.contextMenuClient))
#endif
......
......@@ -33,14 +33,14 @@ namespace WebCore {
using namespace std;
PageGroupLoadDeferrer::PageGroupLoadDeferrer(Page* page, bool deferSelf)
PageGroupLoadDeferrer::PageGroupLoadDeferrer(Page& page, bool deferSelf)
{
const HashSet<Page*>& pages = page->group().pages();
const HashSet<Page*>& pages = page.group().pages();
HashSet<Page*>::const_iterator end = pages.end();
for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) {
Page* otherPage = *it;
if ((deferSelf || otherPage != page)) {
if ((deferSelf || otherPage != &page)) {
if (!otherPage->defersLoading()) {
m_deferredFrames.append(&otherPage->mainFrame());
......
......@@ -31,7 +31,7 @@ namespace WebCore {
class PageGroupLoadDeferrer {
WTF_MAKE_NONCOPYABLE(PageGroupLoadDeferrer);
public:
PageGroupLoadDeferrer(Page*, bool deferSelf);
PageGroupLoadDeferrer(Page&, bool deferSelf);
~PageGroupLoadDeferrer();
private:
......
......@@ -56,7 +56,7 @@ DragOperation DragController::dragOperation(DragData* dragData)
{
ASSERT(dragData);
if ((dragData->flags() & DragApplicationIsModal) || !dragData->containsURL(&m_page->mainFrame()))
if ((dragData->flags() & DragApplicationIsModal) || !dragData->containsURL(&m_page.mainFrame()))
return DragOperationNone;
if (!m_documentUnderMouse || (!(dragData->flags() & (DragApplicationHasAttachedSheet | DragApplicationIsSource))))
......@@ -80,13 +80,13 @@ void DragController::cleanupAfterSystemDrag()
// call it anyway to be on the safe side.
// We don't want to do this for WebKit2, since the client call to start the drag
// is asynchronous.
if (m_page->mainFrame().view()->platformWidget())
if (m_page.mainFrame().view()->platformWidget())
dragEnded();
}
void DragController::declareAndWriteDragImage(Clipboard* clipboard, Element* element, const KURL& url, const String& label)
{
client()->declareAndWriteDragImage(clipboard->pasteboard().name(), kit(element), url, label, element->document().frame());
m_client.declareAndWriteDragImage(clipboard->pasteboard().name(), kit(element), url, label, element->document().frame());
}
} // namespace WebCore
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment