Commit ef7cefa6 authored by akling@apple.com's avatar akling@apple.com

FocusController::focusedOrMainFrame() should return a reference.

<https://webkit.org/b/120339>

Reviewed by Antti Koivisto.

Now that Page::mainFrame() returns a reference, we can make this return a reference
too, since there's always either a focused or a main frame.

One hectogram of null checks removed as a result.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154678 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a5dea8b3
2013-08-26 Andreas Kling <akling@apple.com>
FocusController::focusedOrMainFrame() should return a reference.
<https://webkit.org/b/120339>
Reviewed by Antti Koivisto.
Now that Page::mainFrame() returns a reference, we can make this return a reference
too, since there's always either a focused or a main frame.
One hectogram of null checks removed as a result.
2013-08-26 Andreas Kling <akling@apple.com>
Document's renderer is always a RenderView.
......@@ -161,7 +161,7 @@ AccessibilityObject* AXObjectCache::focusedUIElementForPage(const Page* page)
return 0;
// get the focused node in the page
Document* focusedDocument = page->focusController().focusedOrMainFrame()->document();
Document* focusedDocument = page->focusController().focusedOrMainFrame().document();
Element* focusedElement = focusedDocument->focusedElement();
if (focusedElement && isHTMLAreaElement(focusedElement))
return focusedImageMapUIElement(toHTMLAreaElement(focusedElement));
......
......@@ -984,7 +984,7 @@ bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectIn
// Reveal the current selection
if (Frame* editedFrame = document->frame())
if (Page* page = editedFrame->page())
page->focusController().focusedOrMainFrame()->selection().revealSelection(ScrollAlignment::alignCenterIfNeeded);
page->focusController().focusedOrMainFrame().selection().revealSelection(ScrollAlignment::alignCenterIfNeeded);
}
}
......
......@@ -84,7 +84,7 @@ void CachedPage::restore(Page* page)
// Restore the focus appearance for the focused element.
// FIXME: Right now we don't support pages w/ frames in the b/f cache. This may need to be tweaked when we add support for that.
Document* focusedDocument = page->focusController().focusedOrMainFrame()->document();
Document* focusedDocument = page->focusController().focusedOrMainFrame().document();
if (Element* element = focusedDocument->focusedElement())
element->updateFocusAppearance(true);
......
......@@ -1965,9 +1965,9 @@ bool EventHandler::handlePasteGlobalSelection(const PlatformMouseEvent& mouseEve
if (!m_frame->page())
return false;
Frame* focusFrame = m_frame->page()->focusController().focusedOrMainFrame();
Frame& focusFrame = m_frame->page()->focusController().focusedOrMainFrame();
// Do not paste here if the focus was moved somewhere else.
if (m_frame == focusFrame && m_frame->editor().client()->supportsGlobalSelection())
if (m_frame == &focusFrame && m_frame->editor().client()->supportsGlobalSelection())
return m_frame->editor().command(ASCIILiteral("PasteGlobalSelection")).execute();
return false;
......@@ -3336,7 +3336,7 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) {
node->dispatchEvent(keydown, IGNORE_EXCEPTION);
// If frame changed as a result of keydown dispatch, then return true to avoid sending a subsequent keypress message to the new frame.
bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->focusController().focusedOrMainFrame();
bool changedFocusedFrame = m_frame->page() && m_frame != &m_frame->page()->focusController().focusedOrMainFrame();
return keydown->defaultHandled() || keydown->defaultPrevented() || changedFocusedFrame;
}
......@@ -3358,7 +3358,7 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
node->dispatchEvent(keydown, IGNORE_EXCEPTION);
// If frame changed as a result of keydown dispatch, then return early to avoid sending a subsequent keypress message to the new frame.
bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->focusController().focusedOrMainFrame();
bool changedFocusedFrame = m_frame->page() && m_frame != &m_frame->page()->focusController().focusedOrMainFrame();
bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented() || changedFocusedFrame;
if (handledByInputMethod || (keydownResult && !backwardCompatibilityMode))
return keydownResult;
......
......@@ -204,11 +204,11 @@ void FocusController::setFocusedFrame(PassRefPtr<Frame> frame)
m_isChangingFocusedFrame = false;
}
Frame* FocusController::focusedOrMainFrame() const
Frame& FocusController::focusedOrMainFrame() const
{
if (Frame* frame = focusedFrame())
return frame;
return &m_page->mainFrame();
return *frame;
return m_page->mainFrame();
}
void FocusController::setFocused(bool focused)
......@@ -219,7 +219,7 @@ void FocusController::setFocused(bool focused)
m_isFocused = focused;
if (!m_isFocused)
focusedOrMainFrame()->eventHandler().stopAutoscrollTimer();
focusedOrMainFrame().eventHandler().stopAutoscrollTimer();
if (!m_focusedFrame)
setFocusedFrame(&m_page->mainFrame());
......@@ -255,8 +255,8 @@ bool FocusController::setInitialFocus(FocusDirection direction, KeyboardEvent* e
// If focus is being set initially, accessibility needs to be informed that system focus has moved
// into the web area again, even if focus did not change within WebCore. PostNotification is called instead
// of handleFocusedUIElementChanged, because this will send the notification even if the element is the same.
if (AXObjectCache* cache = focusedOrMainFrame()->document()->existingAXObjectCache())
cache->postNotification(focusedOrMainFrame()->document(), AXObjectCache::AXFocusedUIElementChanged, true);
if (AXObjectCache* cache = focusedOrMainFrame().document()->existingAXObjectCache())
cache->postNotification(focusedOrMainFrame().document(), AXObjectCache::AXFocusedUIElementChanged, true);
return didAdvanceFocus;
}
......@@ -281,16 +281,15 @@ bool FocusController::advanceFocus(FocusDirection direction, KeyboardEvent* even
bool FocusController::advanceFocusInDocumentOrder(FocusDirection direction, KeyboardEvent* event, bool initialFocus)
{
Frame* frame = focusedOrMainFrame();
ASSERT(frame);
Document* document = frame->document();
Frame& frame = focusedOrMainFrame();
Document* document = frame.document();
Node* currentNode = document->focusedElement();
// FIXME: Not quite correct when it comes to focus transitions leaving/entering the WebView itself
bool caretBrowsing = frame->settings().caretBrowsingEnabled();
bool caretBrowsing = frame.settings().caretBrowsingEnabled();
if (caretBrowsing && !currentNode)
currentNode = frame->selection().start().deprecatedNode();
currentNode = frame.selection().start().deprecatedNode();
document->updateLayoutIgnorePendingStylesheets();
......@@ -349,8 +348,8 @@ bool FocusController::advanceFocusInDocumentOrder(FocusDirection direction, Keyb
if (caretBrowsing) {
Position position = firstPositionInOrBeforeNode(element.get());
VisibleSelection newSelection(position, position, DOWNSTREAM);
if (frame->selection().shouldChangeSelection(newSelection))
frame->selection().setSelection(newSelection);
if (frame.selection().shouldChangeSelection(newSelection))
frame.selection().setSelection(newSelection);
}
element->focus(false, direction);
......@@ -660,7 +659,7 @@ void FocusController::setActive(bool active)
}
}
focusedOrMainFrame()->selection().pageActivationChanged();
focusedOrMainFrame().selection().pageActivationChanged();
if (m_focusedFrame && isFocused())
dispatchEventsOnWindowAndFocusedElement(m_focusedFrame->document(), active);
......@@ -828,7 +827,7 @@ bool FocusController::advanceFocusDirectionallyInContainer(Node* container, cons
}
// Navigate into a new frame.
LayoutRect rect;
Element* focusedElement = focusedOrMainFrame()->document()->focusedElement();
Element* focusedElement = focusedOrMainFrame().document()->focusedElement();
if (focusedElement && !hasOffscreenRect(focusedElement))
rect = nodeRectInAbsoluteCoordinates(focusedElement, true /* ignore border */);
frameElement->contentFrame()->document()->updateLayoutIgnorePendingStylesheets();
......@@ -846,7 +845,7 @@ bool FocusController::advanceFocusDirectionallyInContainer(Node* container, cons
}
// Navigate into a new scrollable container.
LayoutRect startingRect;
Element* focusedElement = focusedOrMainFrame()->document()->focusedElement();
Element* focusedElement = focusedOrMainFrame().document()->focusedElement();
if (focusedElement && !hasOffscreenRect(focusedElement))
startingRect = nodeRectInAbsoluteCoordinates(focusedElement, true);
return advanceFocusDirectionallyInContainer(focusCandidate.visibleNode, startingRect, direction, event);
......@@ -867,10 +866,7 @@ bool FocusController::advanceFocusDirectionallyInContainer(Node* container, cons
bool FocusController::advanceFocusDirectionally(FocusDirection direction, KeyboardEvent* event)
{
Frame* curFrame = focusedOrMainFrame();
ASSERT(curFrame);
Document* focusedDocument = curFrame->document();
Document* focusedDocument = focusedOrMainFrame().document();
if (!focusedDocument)
return false;
......
......@@ -66,7 +66,7 @@ public:
void setFocusedFrame(PassRefPtr<Frame>);
Frame* focusedFrame() const { return m_focusedFrame.get(); }
Frame* focusedOrMainFrame() const;
Frame& focusedOrMainFrame() const;
bool setInitialFocus(FocusDirection, KeyboardEvent*);
bool advanceFocus(FocusDirection, KeyboardEvent*, bool initialFocus = false);
......
......@@ -565,7 +565,7 @@ bool Page::findString(const String& target, FindOptions options)
return false;
bool shouldWrap = options & WrapAround;
Frame* frame = focusController().focusedOrMainFrame();
Frame* frame = &focusController().focusedOrMainFrame();
Frame* startFrame = frame;
do {
if (frame->editor().findString(target, (options & ~WrapAround) | StartInSelection)) {
......@@ -697,7 +697,7 @@ void Page::unmarkAllTextMatches()
const VisibleSelection& Page::selection() const
{
return focusController().focusedOrMainFrame()->selection().selection();
return focusController().focusedOrMainFrame().selection().selection();
}
void Page::setDefersLoading(bool defers)
......
......@@ -299,7 +299,7 @@ void DumpRenderTreeSupportEfl::executeCoreCommandByName(const Evas_Object* ewkVi
{
DRT_SUPPRT_PAGE_GET_OR_RETURN(ewkView, page);
page->focusController().focusedOrMainFrame()->editor().command(name).execute(value);
page->focusController().focusedOrMainFrame().editor().command(name).execute(value);
}
bool DumpRenderTreeSupportEfl::findString(const Evas_Object* ewkView, const String& text, WebCore::FindOptions options)
......@@ -348,7 +348,7 @@ bool DumpRenderTreeSupportEfl::isCommandEnabled(const Evas_Object* ewkView, cons
{
DRT_SUPPRT_PAGE_GET_OR_RETURN(ewkView, page, false);
return page->focusController().focusedOrMainFrame()->editor().command(name).isEnabled();
return page->focusController().focusedOrMainFrame().editor().command(name).isEnabled();
}
void DumpRenderTreeSupportEfl::forceLayout(Evas_Object* ewkFrame)
......@@ -565,10 +565,7 @@ void DumpRenderTreeSupportEfl::setComposition(Evas_Object* ewkView, const char*
{
DRT_SUPPRT_PAGE_GET_OR_RETURN(ewkView, page);
if (!page->focusController().focusedOrMainFrame())
return;
WebCore::Editor& editor = page->focusController().focusedOrMainFrame()->editor();
WebCore::Editor& editor = page->focusController().focusedOrMainFrame().editor();
if (!editor.canEdit() && !editor.hasComposition())
return;
......@@ -582,10 +579,7 @@ bool DumpRenderTreeSupportEfl::hasComposition(const Evas_Object* ewkView)
{
DRT_SUPPRT_PAGE_GET_OR_RETURN(ewkView, page, false);
if (!page->focusController().focusedOrMainFrame())
return false;
return page->focusController().focusedOrMainFrame()->editor().hasComposition();
return page->focusController().focusedOrMainFrame().editor().hasComposition();
}
bool DumpRenderTreeSupportEfl::compositionRange(Evas_Object* ewkView, int* start, int* length)
......@@ -594,10 +588,7 @@ bool DumpRenderTreeSupportEfl::compositionRange(Evas_Object* ewkView, int* start
DRT_SUPPRT_PAGE_GET_OR_RETURN(ewkView, page, false);
if (!page->focusController().focusedOrMainFrame())
return false;
WebCore::Editor& editor = page->focusController().focusedOrMainFrame()->editor();
WebCore::Editor& editor = page->focusController().focusedOrMainFrame().editor();
if (!editor.hasComposition())
return false;
......@@ -610,10 +601,7 @@ void DumpRenderTreeSupportEfl::confirmComposition(Evas_Object* ewkView, const ch
{
DRT_SUPPRT_PAGE_GET_OR_RETURN(ewkView, page);
if (!page->focusController().focusedOrMainFrame())
return;
WebCore::Editor& editor = page->focusController().focusedOrMainFrame()->editor();
WebCore::Editor& editor = page->focusController().focusedOrMainFrame().editor();
if (!editor.hasComposition()) {
editor.insertText(String::fromUTF8(text), 0);
......@@ -631,19 +619,16 @@ WebCore::IntRect DumpRenderTreeSupportEfl::firstRectForCharacterRange(Evas_Objec
{
DRT_SUPPRT_PAGE_GET_OR_RETURN(ewkView, page, WebCore::IntRect());
if (!page->focusController().focusedOrMainFrame())
return WebCore::IntRect();
if ((location + length < location) && (location + length))
length = 0;
WebCore::Frame* frame = page->focusController().focusedOrMainFrame();
WebCore::Frame& frame = page->focusController().focusedOrMainFrame();
RefPtr<WebCore::Range> range = WebCore::TextIterator::rangeFromLocationAndLength(frame->selection().rootEditableElementOrDocumentElement(), location, length);
RefPtr<WebCore::Range> range = WebCore::TextIterator::rangeFromLocationAndLength(frame.selection().rootEditableElementOrDocumentElement(), location, length);
if (!range)
return WebCore::IntRect();
return frame->editor().firstRectForRange(range.get());
return frame.editor().firstRectForRange(range.get());
}
bool DumpRenderTreeSupportEfl::selectedRange(Evas_Object* ewkView, int* start, int* length)
......@@ -653,16 +638,13 @@ bool DumpRenderTreeSupportEfl::selectedRange(Evas_Object* ewkView, int* start, i
DRT_SUPPRT_PAGE_GET_OR_RETURN(ewkView, page, false);
if (!page->focusController().focusedOrMainFrame())
return false;
WebCore::Frame* frame = page->focusController().focusedOrMainFrame();
RefPtr<WebCore::Range> range = frame->selection().toNormalizedRange().get();
WebCore::Frame& frame = page->focusController().focusedOrMainFrame();
RefPtr<WebCore::Range> range = frame.selection().toNormalizedRange().get();
if (!range)
return false;
WebCore::Element* selectionRoot = frame->selection().rootEditableElement();
WebCore::Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
WebCore::Element* selectionRoot = frame.selection().rootEditableElement();
WebCore::Element* scope = selectionRoot ? selectionRoot : frame.document()->documentElement();
RefPtr<WebCore::Range> testRange = WebCore::Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
*start = WebCore::TextIterator::rangeLength(testRange.get());
......
......@@ -1573,7 +1573,7 @@ const char* ewk_view_selection_get(const Evas_Object* ewkView)
{
EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
CString selectedString = priv->page->focusController().focusedOrMainFrame()->editor().selectedText().utf8();
CString selectedString = priv->page->focusController().focusedOrMainFrame().editor().selectedText().utf8();
if (selectedString.isNull())
return 0;
return eina_stringshare_add(selectedString.data());
......@@ -1588,7 +1588,7 @@ Eina_Bool ewk_view_editor_command_execute(const Evas_Object* ewkView, const Ewk_
if (!commandString)
return false;
return priv->page->focusController().focusedOrMainFrame()->editor().command(commandString).execute(WTF::String::fromUTF8(value));
return priv->page->focusController().focusedOrMainFrame().editor().command(commandString).execute(WTF::String::fromUTF8(value));
}
Eina_Bool ewk_view_context_menu_forward_event(Evas_Object* ewkView, const Evas_Event_Mouse_Down* downEvent)
......@@ -2945,16 +2945,15 @@ void ewk_view_input_method_state_set(Evas_Object* ewkView, bool active)
{
EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
EWK_VIEW_PRIV_GET(smartData, priv);
WebCore::Frame* focusedFrame = priv->page->focusController().focusedOrMainFrame();
WebCore::Frame& focusedFrame = priv->page->focusController().focusedOrMainFrame();
priv->imh = 0;
if (focusedFrame
&& focusedFrame->document()
&& focusedFrame->document()->focusedElement()
&& isHTMLInputElement(focusedFrame->document()->focusedElement())) {
if (focusedFrame.document()
&& focusedFrame.document()->focusedElement()
&& isHTMLInputElement(focusedFrame.document()->focusedElement())) {
WebCore::HTMLInputElement* inputElement;
inputElement = static_cast<WebCore::HTMLInputElement*>(focusedFrame->document()->focusedElement());
inputElement = static_cast<WebCore::HTMLInputElement*>(focusedFrame.document()->focusedElement());
if (inputElement) {
// for password fields, active == false
if (!active) {
......@@ -4011,11 +4010,9 @@ void ewk_view_text_direction_set(Evas_Object* ewkView, Ewk_Text_Direction direct
// the text direction of the selected node and updates its DOM "dir"
// attribute and its CSS "direction" property.
// So, we just call the function as Safari does.
WebCore::Frame* focusedFrame = priv->page->focusController().focusedOrMainFrame();
if (!focusedFrame)
return;
WebCore::Frame& focusedFrame = priv->page->focusController().focusedOrMainFrame();
WebCore::Editor& editor = focusedFrame->editor();
WebCore::Editor& editor = focusedFrame.editor();
if (!editor.canEdit())
return;
......
......@@ -623,8 +623,8 @@ void ChromeClient::paint(WebCore::Timer<ChromeClient>*)
// We update the IM context window location here, because we want it to be
// synced with cursor movement. For instance, a text field can move without
// the selection changing.
Frame* focusedFrame = core(m_webView)->focusController().focusedOrMainFrame();
if (focusedFrame && focusedFrame->editor().canEdit())
Frame& focusedFrame = core(m_webView)->focusController().focusedOrMainFrame();
if (focusedFrame.editor().canEdit())
m_webView->priv->imFilter.setCursorRect(frame.selection().absoluteCaretBounds());
}
......
......@@ -276,7 +276,7 @@ void DumpRenderTreeSupportGtk::executeCoreCommandByName(WebKitWebView* webView,
g_return_if_fail(name);
g_return_if_fail(value);
core(webView)->focusController().focusedOrMainFrame()->editor().command(name).execute(value);
core(webView)->focusController().focusedOrMainFrame().editor().command(name).execute(value);
}
bool DumpRenderTreeSupportGtk::isCommandEnabled(WebKitWebView* webView, const gchar* name)
......@@ -284,7 +284,7 @@ bool DumpRenderTreeSupportGtk::isCommandEnabled(WebKitWebView* webView, const gc
g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
g_return_val_if_fail(name, FALSE);
return core(webView)->focusController().focusedOrMainFrame()->editor().command(name).isEnabled();
return core(webView)->focusController().focusedOrMainFrame().editor().command(name).isEnabled();
}
void DumpRenderTreeSupportGtk::setComposition(WebKitWebView* webView, const char* text, int start, int length)
......@@ -292,11 +292,8 @@ void DumpRenderTreeSupportGtk::setComposition(WebKitWebView* webView, const char
g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
g_return_if_fail(text);
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
if (!frame)
return;
Editor& editor = frame->editor();
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
Editor& editor = frame.editor();
if (!editor.canEdit() && !editor.hasComposition())
return;
......@@ -309,11 +306,8 @@ void DumpRenderTreeSupportGtk::setComposition(WebKitWebView* webView, const char
bool DumpRenderTreeSupportGtk::hasComposition(WebKitWebView* webView)
{
g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
if (!frame)
return false;
return frame->editor().hasComposition();
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
return frame.editor().hasComposition();
}
bool DumpRenderTreeSupportGtk::compositionRange(WebKitWebView* webView, int* start, int* length)
......@@ -322,11 +316,8 @@ bool DumpRenderTreeSupportGtk::compositionRange(WebKitWebView* webView, int* sta
*start = *length = 0;
g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
if (!frame)
return false;
Editor& editor = frame->editor();
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
Editor& editor = frame.editor();
if (!editor.hasComposition())
return false;
......@@ -339,11 +330,8 @@ void DumpRenderTreeSupportGtk::confirmComposition(WebKitWebView* webView, const
{
g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
if (!frame)
return;
Editor& editor = frame->editor();
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
Editor& editor = frame.editor();
if (!editor.hasComposition()) {
editor.insertText(String::fromUTF8(text), 0);
......@@ -359,11 +347,8 @@ void DumpRenderTreeSupportGtk::confirmComposition(WebKitWebView* webView, const
void DumpRenderTreeSupportGtk::doCommand(WebKitWebView* webView, const char* command)
{
g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
if (!frame)
return;
Editor& editor = frame->editor();
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
Editor& editor = frame.editor();
String commandString(command);
// Remove ending : here.
......@@ -387,13 +372,10 @@ bool DumpRenderTreeSupportGtk::firstRectForCharacterRange(WebKitWebView* webView
if ((location + length < location) && (location + length))
length = 0;
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
if (!frame)
return false;
Editor& editor = frame->editor();
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
Editor& editor = frame.editor();
RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(frame->selection().rootEditableElementOrDocumentElement(), location, length);
RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(frame.selection().rootEditableElementOrDocumentElement(), location, length);
if (!range)
return false;
......@@ -406,16 +388,14 @@ bool DumpRenderTreeSupportGtk::selectedRange(WebKitWebView* webView, int* start,
g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
g_return_val_if_fail(start && length, false);
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
if (!frame)
return false;
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
RefPtr<Range> range = frame->selection().toNormalizedRange().get();
RefPtr<Range> range = frame.selection().toNormalizedRange().get();
if (!range)
return false;
Element* selectionRoot = frame->selection().rootEditableElement();
Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
Element* selectionRoot = frame.selection().rootEditableElement();
Element* scope = selectionRoot ? selectionRoot : frame.document()->documentElement();
RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
ASSERT(testRange->startContainer() == scope);
......
......@@ -212,11 +212,10 @@ static void collapseSelection(GtkClipboard* clipboard, WebKitWebView* webView)
if (!corePage)
return;
Frame* frame = corePage->focusController().focusedOrMainFrame();
Frame& frame = corePage->focusController().focusedOrMainFrame();
// Collapse the selection without clearing it
ASSERT(frame);
frame->selection().setBase(frame->selection().extent(), frame->selection().affinity());
frame.selection().setBase(frame.selection().extent(), frame.selection().affinity());
}
#if PLATFORM(X11)
......@@ -228,13 +227,13 @@ static void setSelectionPrimaryClipboardIfNeeded(WebKitWebView* webView)
GtkClipboard* clipboard = gtk_widget_get_clipboard(GTK_WIDGET(webView), GDK_SELECTION_PRIMARY);
DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
WebCore::Page* corePage = core(webView);
Frame* targetFrame = corePage->focusController().focusedOrMainFrame();
Frame& targetFrame = corePage->focusController().focusedOrMainFrame();
if (!targetFrame->selection().isRange())
if (!targetFrame.selection().isRange())
return;
dataObject->clearAll();
dataObject->setRange(targetFrame->selection().toNormalizedRange());
dataObject->setRange(targetFrame.selection().toNormalizedRange());
viewSettingClipboard = webView;
GClosure* callback = g_cclosure_new_object(G_CALLBACK(collapseSelection), G_OBJECT(webView));
......
......@@ -39,7 +39,7 @@ Frame* WebViewInputMethodFilter::focusedOrMainFrame()
if (!page)
return 0;
return page->focusController().focusedOrMainFrame();
return &page->focusController().focusedOrMainFrame();
}
void WebViewInputMethodFilter::setWebView(WebKitWebView* webView)
......
......@@ -485,8 +485,8 @@ void webkit_web_inspector_show(WebKitWebInspector* webInspector)
WebKitWebInspectorPrivate* priv = webInspector->priv;
Frame* frame = priv->page->focusController().focusedOrMainFrame();
FrameView* view = frame->view();
Frame& frame = priv->page->focusController().focusedOrMainFrame();
FrameView* view = frame.view();
if (!view)
return;
......@@ -535,8 +535,8 @@ void webkit_web_inspector_inspect_coordinates(WebKitWebInspector* webInspector,
WebKitWebInspectorPrivate* priv = webInspector->priv;
Frame* frame = priv->page->focusController().focusedOrMainFrame();
FrameView* view = frame->view();
Frame& frame = priv->page->focusController().focusedOrMainFrame();
FrameView* view = frame.view();
if (!view)
return;
......@@ -545,7 +545,7 @@ void webkit_web_inspector_inspect_coordinates(WebKitWebInspector* webInspector,
IntPoint documentPoint = view->windowToContents(IntPoint(static_cast<int>(x), static_cast<int>(y)));
HitTestResult result(documentPoint);
frame->contentRenderer()->layer()->hitTest(request, result);
frame.contentRenderer()->layer()->hitTest(request, result);
priv->page->inspectorController()->inspect(result.innerNonSharedNode());
}
......
......@@ -361,7 +361,7 @@ static gboolean webkit_web_view_forward_context_menu_event(WebKitWebView* webVie
if (!targetFrame)
targetFrame = mainFrame;
focusedFrame = page->focusController().focusedOrMainFrame();
focusedFrame = &page->focusController().focusedOrMainFrame();
if (targetFrame != focusedFrame) {
page->focusController().setFocusedFrame(targetFrame);
focusedFrame = targetFrame;
......@@ -447,10 +447,10 @@ static IntPoint getLocationForKeyboardGeneratedContextMenu(Frame* frame)
static gboolean webkit_web_view_popup_menu_handler(GtkWidget* widget)
{
Frame* frame = core(WEBKIT_WEB_VIEW(widget))->focusController().focusedOrMainFrame();
IntPoint location = getLocationForKeyboardGeneratedContextMenu(frame);
Frame& frame = core(WEBKIT_WEB_VIEW(widget))->focusController().focusedOrMainFrame();
IntPoint location = getLocationForKeyboardGeneratedContextMenu(&frame);
FrameView* view = frame->view();
FrameView* view = frame.view();
if (!view)
return FALSE;
......@@ -1179,32 +1179,32 @@ static gboolean webkit_web_view_real_console_message(WebKitWebView* webView, con
static void webkit_web_view_real_select_all(WebKitWebView* webView)
{
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
frame->editor().command("SelectAll").execute();
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
frame.editor().command("SelectAll").execute();
}
static void webkit_web_view_real_cut_clipboard(WebKitWebView* webView)
{
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
frame->editor().command("Cut").execute();
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
frame.editor().command("Cut").execute();
}
static void webkit_web_view_real_copy_clipboard(WebKitWebView* webView)
{
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
frame->editor().command("Copy").execute();
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
frame.editor().command("Copy").execute();
}
static void webkit_web_view_real_undo(WebKitWebView* webView)
{
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
frame->editor().command("Undo").execute();
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
frame.editor().command("Undo").execute();
}
static void webkit_web_view_real_redo(WebKitWebView* webView)
{
Frame* frame = core(webView)->focusController().focusedOrMainFrame();
frame->editor().command("Redo").execute();
Frame& frame = core(webView)->focusController().focusedOrMainFrame();
frame.editor().command("Redo").execute();