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

ContextMenuController should hold onto a Page&

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

Reviewed by Anders Carlsson.

* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::ContextMenuController):
(WebCore::ContextMenuController::~ContextMenuController):
(WebCore::ContextMenuController::showContextMenu):
(WebCore::ContextMenuController::contextMenuItemSelected):
(WebCore::ContextMenuController::checkOrEnableIfNeeded):
(WebCore::ContextMenuController::showContextMenuAt):
* page/ContextMenuController.h:
Store the Page and ContextMenuClient as references.

* page/Page.cpp:
(WebCore::Page::Page):
Pass the Page and ContextMenuClient as references and switch to using createOwned<>().


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@155723 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0616a29f
2013-09-13 Sam Weinig <sam@webkit.org>
ContextMenuController should hold onto a Page&
https://bugs.webkit.org/show_bug.cgi?id=121320
Reviewed by Anders Carlsson.
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::ContextMenuController):
(WebCore::ContextMenuController::~ContextMenuController):
(WebCore::ContextMenuController::showContextMenu):
(WebCore::ContextMenuController::contextMenuItemSelected):
(WebCore::ContextMenuController::checkOrEnableIfNeeded):
(WebCore::ContextMenuController::showContextMenuAt):
* page/ContextMenuController.h:
Store the Page and ContextMenuClient as references.
* page/Page.cpp:
(WebCore::Page::Page):
Pass the Page and ContextMenuClient as references and switch to using createOwned<>().
2013-09-13 Tim Horton <timothy_horton@apple.com>
Apply OVERRIDE and FINAL to Image subclasses and clean them up
......@@ -81,22 +81,15 @@ using namespace Unicode;
namespace WebCore {
ContextMenuController::ContextMenuController(Page* page, ContextMenuClient* client)
ContextMenuController::ContextMenuController(Page& page, ContextMenuClient& client)
: m_page(page)
, m_client(client)
{
ASSERT_ARG(page, page);
ASSERT_ARG(client, client);
}
ContextMenuController::~ContextMenuController()
{
m_client->contextMenuDestroyed();
}
PassOwnPtr<ContextMenuController> ContextMenuController::create(Page* page, ContextMenuClient* client)
{
return adoptPtr(new ContextMenuController(page, client));
m_client.contextMenuDestroyed();
}
void ContextMenuController::clearContextMenu()
......@@ -165,14 +158,14 @@ PassOwnPtr<ContextMenu> ContextMenuController::createContextMenu(Event* event)
void ContextMenuController::showContextMenu(Event* event)
{
#if ENABLE(INSPECTOR)
if (m_page->inspectorController()->enabled())
if (m_page.inspectorController()->enabled())
addInspectElementItem();
#endif
#if USE(CROSS_PLATFORM_CONTEXT_MENUS)
m_contextMenu = m_client->customizeMenu(m_contextMenu.release());
m_contextMenu = m_client.customizeMenu(m_contextMenu.release());
#else
PlatformMenuDescription customMenu = m_client->getCustomMenuFromDefaultItems(m_contextMenu.get());
PlatformMenuDescription customMenu = m_client.getCustomMenuFromDefaultItems(m_contextMenu.get());
m_contextMenu->setPlatformDescription(customMenu);
#endif
event->setDefaultHandled();
......@@ -209,7 +202,7 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
if (item->action() >= ContextMenuItemBaseApplicationTag) {
m_client->contextMenuItemSelected(item, m_contextMenu.get());
m_client.contextMenuItemSelected(item, m_contextMenu.get());
return;
}
......@@ -229,7 +222,7 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
break;
case ContextMenuItemTagDownloadLinkToDisk:
// FIXME: Some day we should be able to do this from within WebCore. (Bug 117709)
m_client->downloadURL(m_hitTestResult.absoluteLinkURL());
m_client.downloadURL(m_hitTestResult.absoluteLinkURL());
break;
case ContextMenuItemTagCopyLinkToClipboard:
frame->editor().copyURL(m_hitTestResult.absoluteLinkURL(), m_hitTestResult.textContent());
......@@ -239,7 +232,7 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
break;
case ContextMenuItemTagDownloadImageToDisk:
// FIXME: Some day we should be able to do this from within WebCore. (Bug 117709)
m_client->downloadURL(m_hitTestResult.absoluteImageURL());
m_client.downloadURL(m_hitTestResult.absoluteImageURL());
break;
case ContextMenuItemTagCopyImageToClipboard:
// FIXME: The Pasteboard class is not written yet
......@@ -256,7 +249,7 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
break;
case ContextMenuItemTagDownloadMediaToDisk:
// FIXME: Some day we should be able to do this from within WebCore. (Bug 117709)
m_client->downloadURL(m_hitTestResult.absoluteMediaURL());
m_client.downloadURL(m_hitTestResult.absoluteMediaURL());
break;
case ContextMenuItemTagCopyMediaLinkToClipboard:
frame->editor().copyURL(m_hitTestResult.absoluteMediaURL(), m_hitTestResult.textContent());
......@@ -380,11 +373,11 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
frame->editor().learnSpelling();
break;
case ContextMenuItemTagSearchWeb:
m_client->searchWithGoogle(frame);
m_client.searchWithGoogle(frame);
break;
case ContextMenuItemTagLookUpInDictionary:
// FIXME: Some day we may be able to do this from within WebCore.
m_client->lookUpInDictionary(frame);
m_client.lookUpInDictionary(frame);
break;
case ContextMenuItemTagOpenLink:
if (Frame* targetFrame = m_hitTestResult.targetFrame())
......@@ -415,11 +408,11 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
selectedRange = document.createRange();
selectedRange->selectNode(document.documentElement(), IGNORE_EXCEPTION);
}
m_client->speak(plainText(selectedRange.get()));
m_client.speak(plainText(selectedRange.get()));
break;
}
case ContextMenuItemTagStopSpeaking:
m_client->stopSpeaking();
m_client.stopSpeaking();
break;
case ContextMenuItemTagDefaultDirection:
frame->editor().setBaseWritingDirection(NaturalWritingDirection);
......@@ -441,7 +434,7 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
break;
#if PLATFORM(MAC)
case ContextMenuItemTagSearchInSpotlight:
m_client->searchWithSpotlight();
m_client.searchWithSpotlight();
break;
#endif
case ContextMenuItemTagShowSpellingPanel:
......@@ -1285,7 +1278,7 @@ void ContextMenuController::checkOrEnableIfNeeded(ContextMenuItem& item) const
shouldCheck = frame->editor().isAutomaticTextReplacementEnabled();
break;
case ContextMenuItemTagStopSpeaking:
shouldEnable = client() && client()->isSpeaking();
shouldEnable = m_client.isSpeaking();
break;
#else // PLATFORM(MAC) ends here
case ContextMenuItemTagStopSpeaking:
......@@ -1420,8 +1413,8 @@ void ContextMenuController::showContextMenuAt(Frame* frame, const IntPoint& clic
// Simulate a click in the middle of the accessibility object.
PlatformMouseEvent mouseEvent(clickPoint, clickPoint, RightButton, PlatformEvent::MousePressed, 1, false, false, false, false, currentTime());
bool handled = frame->eventHandler().sendContextMenuEvent(mouseEvent);
if (handled && client())
client()->showContextMenu();
if (handled)
m_client.showContextMenu();
}
#endif
......
......@@ -46,12 +46,9 @@ namespace WebCore {
class ContextMenuController {
WTF_MAKE_NONCOPYABLE(ContextMenuController); WTF_MAKE_FAST_ALLOCATED;
public:
ContextMenuController(Page&, ContextMenuClient&);
~ContextMenuController();
static PassOwnPtr<ContextMenuController> create(Page*, ContextMenuClient*);
ContextMenuClient* client() const { return m_client; }
ContextMenu* contextMenu() const { return m_contextMenu.get(); }
void clearContextMenu();
......@@ -72,8 +69,6 @@ namespace WebCore {
#endif
private:
ContextMenuController(Page*, ContextMenuClient*);
PassOwnPtr<ContextMenu> createContextMenu(Event*);
void showContextMenu(Event*);
......@@ -91,8 +86,8 @@ namespace WebCore {
void createAndAppendUnicodeSubMenu(ContextMenuItem&);
#endif
Page* m_page;
ContextMenuClient* m_client;
Page& m_page;
ContextMenuClient& m_client;
OwnPtr<ContextMenu> m_contextMenu;
RefPtr<ContextMenuProvider> m_menuProvider;
HitTestResult m_hitTestResult;
......
......@@ -131,7 +131,7 @@ Page::Page(PageClients& pageClients)
#endif
, m_focusController(FocusController::create(this))
#if ENABLE(CONTEXT_MENUS)
, m_contextMenuController(ContextMenuController::create(this, pageClients.contextMenuClient))
, m_contextMenuController(createOwned<ContextMenuController>(*this, *pageClients.contextMenuClient))
#endif
#if ENABLE(INSPECTOR)
, m_inspectorController(InspectorController::create(this, pageClients.inspectorClient))
......
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