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

Side by Side Diff: Source/web/WebViewImpl.cpp

Issue 189573002: Convert HTMLFrameOwnerElement and FocusController to use Frame. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Missed a null check 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
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 { 515 {
516 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 516 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
517 return; 517 return;
518 518
519 m_page->contextMenuController().clearContextMenu(); 519 m_page->contextMenuController().clearContextMenu();
520 520
521 PlatformMouseEventBuilder pme(mainFrameImpl()->frameView(), event); 521 PlatformMouseEventBuilder pme(mainFrameImpl()->frameView(), event);
522 522
523 // Find the right target frame. See issue 1186900. 523 // Find the right target frame. See issue 1186900.
524 HitTestResult result = hitTestResultForWindowPos(pme.position()); 524 HitTestResult result = hitTestResultForWindowPos(pme.position());
525 LocalFrame* targetFrame; 525 Frame* targetFrame;
526 if (result.innerNonSharedNode()) 526 if (result.innerNonSharedNode())
527 targetFrame = result.innerNonSharedNode()->document().frame(); 527 targetFrame = result.innerNonSharedNode()->document().frame();
528 else 528 else
529 targetFrame = m_page->focusController().focusedOrMainFrame(); 529 targetFrame = m_page->focusController().focusedOrMainFrame();
530 530
531 if (!targetFrame->isLocalFrame())
532 return;
533
534 LocalFrame* targetLocalFrame = toLocalFrame(targetFrame);
535
531 #if OS(WIN) 536 #if OS(WIN)
532 targetFrame->view()->setCursor(pointerCursor()); 537 targetLocalFrame->view()->setCursor(pointerCursor());
533 #endif 538 #endif
534 539
535 m_contextMenuAllowed = true; 540 m_contextMenuAllowed = true;
536 targetFrame->eventHandler().sendContextMenuEvent(pme); 541 targetLocalFrame->eventHandler().sendContextMenuEvent(pme);
537 m_contextMenuAllowed = false; 542 m_contextMenuAllowed = false;
538 // Actually showing the context menu is handled by the ContextMenuClient 543 // Actually showing the context menu is handled by the ContextMenuClient
539 // implementation... 544 // implementation...
540 } 545 }
541 546
542 void WebViewImpl::handleMouseUp(LocalFrame& mainFrame, const WebMouseEvent& even t) 547 void WebViewImpl::handleMouseUp(LocalFrame& mainFrame, const WebMouseEvent& even t)
543 { 548 {
544 PageWidgetEventHandler::handleMouseUp(mainFrame, event); 549 PageWidgetEventHandler::handleMouseUp(mainFrame, event);
545 550
546 #if OS(WIN) 551 #if OS(WIN)
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 844
840 void WebViewImpl::setShowScrollBottleneckRects(bool show) 845 void WebViewImpl::setShowScrollBottleneckRects(bool show)
841 { 846 {
842 if (m_layerTreeView) 847 if (m_layerTreeView)
843 m_layerTreeView->setShowScrollBottleneckRects(show); 848 m_layerTreeView->setShowScrollBottleneckRects(show);
844 m_showScrollBottleneckRects = show; 849 m_showScrollBottleneckRects = show;
845 } 850 }
846 851
847 void WebViewImpl::getSelectionRootBounds(WebRect& bounds) const 852 void WebViewImpl::getSelectionRootBounds(WebRect& bounds) const
848 { 853 {
849 const LocalFrame* frame = focusedWebCoreFrame(); 854 const Frame* frame = focusedWebCoreFrame();
850 if (!frame) 855 if (!frame || !frame->isLocalFrame())
851 return; 856 return;
852 857
853 Element* root = frame->selection().rootEditableElementOrDocumentElement(); 858 Element* root = toLocalFrame(frame)->selection().rootEditableElementOrDocume ntElement();
854 if (!root) 859 if (!root)
855 return; 860 return;
856 861
857 // If the selection is inside a form control, the root will be a <div> that 862 // If the selection is inside a form control, the root will be a <div> that
858 // behaves as the editor but we want to return the actual element's bounds. 863 // behaves as the editor but we want to return the actual element's bounds.
859 // In practice, that means <textarea> and <input> controls that behave like 864 // In practice, that means <textarea> and <input> controls that behave like
860 // a text field. 865 // a text field.
861 Element* shadowHost = root->shadowHost(); 866 Element* shadowHost = root->shadowHost();
862 if (shadowHost 867 if (shadowHost
863 && (isHTMLTextAreaElement(*shadowHost) 868 && (isHTMLTextAreaElement(*shadowHost)
(...skipping 30 matching lines...) Expand all
894 return m_selectPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event) ); 899 return m_selectPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event) );
895 if (m_pagePopup) { 900 if (m_pagePopup) {
896 m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event)); 901 m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event));
897 // We need to ignore the next Char event after this otherwise pressing 902 // We need to ignore the next Char event after this otherwise pressing
898 // enter when selecting an item in the popup will go to the page. 903 // enter when selecting an item in the popup will go to the page.
899 if (WebInputEvent::RawKeyDown == event.type) 904 if (WebInputEvent::RawKeyDown == event.type)
900 m_suppressNextKeypressEvent = true; 905 m_suppressNextKeypressEvent = true;
901 return true; 906 return true;
902 } 907 }
903 908
904 RefPtr<LocalFrame> frame = focusedWebCoreFrame(); 909 // TODO(kenrb): Handle the remote frame case. Possibly move eventHandler() t o Frame?
910 RefPtr<LocalFrame> frame = toLocalFrame(focusedWebCoreFrame());
905 if (!frame) 911 if (!frame)
906 return false; 912 return false;
907 913
908 #if !OS(MACOSX) 914 #if !OS(MACOSX)
909 const WebInputEvent::Type contextMenuTriggeringEventType = 915 const WebInputEvent::Type contextMenuTriggeringEventType =
910 #if OS(WIN) 916 #if OS(WIN)
911 WebInputEvent::KeyUp; 917 WebInputEvent::KeyUp;
912 #else 918 #else
913 WebInputEvent::RawKeyDown; 919 WebInputEvent::RawKeyDown;
914 #endif 920 #endif
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 bool suppress = m_suppressNextKeypressEvent; 955 bool suppress = m_suppressNextKeypressEvent;
950 m_suppressNextKeypressEvent = false; 956 m_suppressNextKeypressEvent = false;
951 957
952 // If there is a select popup, it should be the one processing the event, 958 // If there is a select popup, it should be the one processing the event,
953 // not the page. 959 // not the page.
954 if (m_selectPopup) 960 if (m_selectPopup)
955 return m_selectPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event) ); 961 return m_selectPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event) );
956 if (m_pagePopup) 962 if (m_pagePopup)
957 return m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event)); 963 return m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event));
958 964
959 LocalFrame* frame = focusedWebCoreFrame(); 965 LocalFrame* frame = toLocalFrame(focusedWebCoreFrame());
960 if (!frame) 966 if (!frame)
961 return suppress; 967 return suppress;
962 968
963 EventHandler& handler = frame->eventHandler(); 969 EventHandler& handler = frame->eventHandler();
964 970
965 PlatformKeyboardEventBuilder evt(event); 971 PlatformKeyboardEventBuilder evt(event);
966 if (!evt.isCharacterKey()) 972 if (!evt.isCharacterKey())
967 return true; 973 return true;
968 974
969 // Accesskeys are triggered by char events and can't be suppressed. 975 // Accesskeys are triggered by char events and can't be suppressed.
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 { 1300 {
1295 // The contextMenuController() holds onto the last context menu that was 1301 // The contextMenuController() holds onto the last context menu that was
1296 // popped up on the page until a new one is created. We need to clear 1302 // popped up on the page until a new one is created. We need to clear
1297 // this menu before propagating the event through the DOM so that we can 1303 // this menu before propagating the event through the DOM so that we can
1298 // detect if we create a new menu for this event, since we won't create 1304 // detect if we create a new menu for this event, since we won't create
1299 // a new menu if the DOM swallows the event and the defaultEventHandler does 1305 // a new menu if the DOM swallows the event and the defaultEventHandler does
1300 // not run. 1306 // not run.
1301 page()->contextMenuController().clearContextMenu(); 1307 page()->contextMenuController().clearContextMenu();
1302 1308
1303 m_contextMenuAllowed = true; 1309 m_contextMenuAllowed = true;
1304 LocalFrame* focusedFrame = page()->focusController().focusedOrMainFrame(); 1310 Frame* focusedFrame = page()->focusController().focusedOrMainFrame();
1305 bool handled = focusedFrame->eventHandler().sendContextMenuEventForKey(); 1311 if (!focusedFrame->isLocalFrame())
1312 return false;
1313 bool handled = toLocalFrame(focusedFrame)->eventHandler().sendContextMenuEve ntForKey();
1306 m_contextMenuAllowed = false; 1314 m_contextMenuAllowed = false;
1307 return handled; 1315 return handled;
1308 } 1316 }
1309 #endif 1317 #endif
1310 1318
1311 bool WebViewImpl::keyEventDefault(const WebKeyboardEvent& event) 1319 bool WebViewImpl::keyEventDefault(const WebKeyboardEvent& event)
1312 { 1320 {
1313 LocalFrame* frame = focusedWebCoreFrame(); 1321 LocalFrame* frame = toLocalFrame(focusedWebCoreFrame());
1314 if (!frame) 1322 if (!frame)
1315 return false; 1323 return false;
1316 1324
1317 switch (event.type) { 1325 switch (event.type) {
1318 case WebInputEvent::Char: 1326 case WebInputEvent::Char:
1319 if (event.windowsKeyCode == VKEY_SPACE) { 1327 if (event.windowsKeyCode == VKEY_SPACE) {
1320 int keyCode = ((event.modifiers & WebInputEvent::ShiftKey) ? VKEY_PR IOR : VKEY_NEXT); 1328 int keyCode = ((event.modifiers & WebInputEvent::ShiftKey) ? VKEY_PR IOR : VKEY_NEXT);
1321 return scrollViewWithKeyboard(keyCode, event.modifiers); 1329 return scrollViewWithKeyboard(keyCode, event.modifiers);
1322 } 1330 }
1323 break; 1331 break;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 } 1424 }
1417 1425
1418 void WebViewImpl::hideSelectPopup() 1426 void WebViewImpl::hideSelectPopup()
1419 { 1427 {
1420 if (m_selectPopup) 1428 if (m_selectPopup)
1421 m_selectPopup->hidePopup(); 1429 m_selectPopup->hidePopup();
1422 } 1430 }
1423 1431
1424 bool WebViewImpl::bubblingScroll(ScrollDirection scrollDirection, ScrollGranular ity scrollGranularity) 1432 bool WebViewImpl::bubblingScroll(ScrollDirection scrollDirection, ScrollGranular ity scrollGranularity)
1425 { 1433 {
1426 LocalFrame* frame = focusedWebCoreFrame(); 1434 LocalFrame* frame = toLocalFrame(focusedWebCoreFrame());
1427 if (!frame) 1435 if (!frame)
1428 return false; 1436 return false;
1429 1437
1430 return frame->eventHandler().bubblingScroll(scrollDirection, scrollGranulari ty); 1438 return frame->eventHandler().bubblingScroll(scrollDirection, scrollGranulari ty);
1431 } 1439 }
1432 1440
1433 void WebViewImpl::popupOpened(PopupContainer* popupContainer) 1441 void WebViewImpl::popupOpened(PopupContainer* popupContainer)
1434 { 1442 {
1435 ASSERT(!m_selectPopup); 1443 ASSERT(!m_selectPopup);
1436 m_selectPopup = popupContainer; 1444 m_selectPopup = popupContainer;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 { 1477 {
1470 ASSERT(popup); 1478 ASSERT(popup);
1471 WebPagePopupImpl* popupImpl = toWebPagePopupImpl(popup); 1479 WebPagePopupImpl* popupImpl = toWebPagePopupImpl(popup);
1472 ASSERT(m_pagePopup.get() == popupImpl); 1480 ASSERT(m_pagePopup.get() == popupImpl);
1473 if (m_pagePopup.get() != popupImpl) 1481 if (m_pagePopup.get() != popupImpl)
1474 return; 1482 return;
1475 m_pagePopup->closePopup(); 1483 m_pagePopup->closePopup();
1476 m_pagePopup = nullptr; 1484 m_pagePopup = nullptr;
1477 } 1485 }
1478 1486
1479 LocalFrame* WebViewImpl::focusedWebCoreFrame() const 1487 Frame* WebViewImpl::focusedWebCoreFrame() const
1480 { 1488 {
1481 return m_page ? m_page->focusController().focusedOrMainFrame() : 0; 1489 return m_page ? m_page->focusController().focusedOrMainFrame() : 0;
1482 } 1490 }
1483 1491
1484 WebViewImpl* WebViewImpl::fromPage(Page* page) 1492 WebViewImpl* WebViewImpl::fromPage(Page* page)
1485 { 1493 {
1486 if (!page) 1494 if (!page)
1487 return 0; 1495 return 0;
1488 return static_cast<WebViewImpl*>(page->chrome().client().webView()); 1496 return static_cast<WebViewImpl*>(page->chrome().client().webView());
1489 } 1497 }
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 { 1857 {
1850 TRACE_EVENT_ASYNC_END0("input", "capturing mouse", this); 1858 TRACE_EVENT_ASYNC_END0("input", "capturing mouse", this);
1851 m_mouseCaptureNode = nullptr; 1859 m_mouseCaptureNode = nullptr;
1852 } 1860 }
1853 1861
1854 void WebViewImpl::setFocus(bool enable) 1862 void WebViewImpl::setFocus(bool enable)
1855 { 1863 {
1856 m_page->focusController().setFocused(enable); 1864 m_page->focusController().setFocused(enable);
1857 if (enable) { 1865 if (enable) {
1858 m_page->focusController().setActive(true); 1866 m_page->focusController().setActive(true);
1859 RefPtr<LocalFrame> focusedFrame = m_page->focusController().focusedFrame (); 1867 RefPtr<Frame> focusedFrame = m_page->focusController().focusedFrame();
1860 if (focusedFrame) { 1868 if (focusedFrame && focusedFrame->isLocalFrame()) {
1861 Element* element = focusedFrame->document()->focusedElement(); 1869 LocalFrame* localFrame = toLocalFrame(focusedFrame.get());
1862 if (element && focusedFrame->selection().selection().isNone()) { 1870 Element* element = localFrame->document()->focusedElement();
1871 if (element && localFrame->selection().selection().isNone()) {
1863 // If the selection was cleared while the WebView was not 1872 // If the selection was cleared while the WebView was not
1864 // focused, then the focus element shows with a focus ring but 1873 // focused, then the focus element shows with a focus ring but
1865 // no caret and does respond to keyboard inputs. 1874 // no caret and does respond to keyboard inputs.
1866 if (element->isTextFormControl()) { 1875 if (element->isTextFormControl()) {
1867 element->updateFocusAppearance(true); 1876 element->updateFocusAppearance(true);
1868 } else if (element->isContentEditable()) { 1877 } else if (element->isContentEditable()) {
1869 // updateFocusAppearance() selects all the text of 1878 // updateFocusAppearance() selects all the text of
1870 // contentseditable DIVs. So we set the selection explicitly 1879 // contentseditable DIVs. So we set the selection explicitly
1871 // instead. Note that this has the side effect of moving the 1880 // instead. Note that this has the side effect of moving the
1872 // caret back to the beginning of the text. 1881 // caret back to the beginning of the text.
1873 Position position(element, 0, Position::PositionIsOffsetInAn chor); 1882 Position position(element, 0, Position::PositionIsOffsetInAn chor);
1874 focusedFrame->selection().setSelection(VisibleSelection(posi tion, SEL_DEFAULT_AFFINITY)); 1883 localFrame->selection().setSelection(VisibleSelection(positi on, SEL_DEFAULT_AFFINITY));
1875 } 1884 }
1876 } 1885 }
1877 } 1886 }
1878 m_imeAcceptEvents = true; 1887 m_imeAcceptEvents = true;
1879 } else { 1888 } else {
1880 hidePopups(); 1889 hidePopups();
1881 1890
1882 // Clear focus on the currently focused frame if any. 1891 // Clear focus on the currently focused frame if any.
1883 if (!m_page) 1892 if (!m_page)
1884 return; 1893 return;
1885 1894
1886 LocalFrame* frame = m_page->mainFrame(); 1895 LocalFrame* frame = m_page->mainFrame();
1887 if (!frame) 1896 if (!frame)
1888 return; 1897 return;
1889 1898
1890 RefPtr<LocalFrame> focusedFrame = m_page->focusController().focusedFrame (); 1899 RefPtr<Frame> focusedFrame = m_page->focusController().focusedFrame();
1891 if (focusedFrame) { 1900 if (focusedFrame && focusedFrame->isLocalFrame()) {
1892 // Finish an ongoing composition to delete the composition node. 1901 // Finish an ongoing composition to delete the composition node.
1893 if (focusedFrame->inputMethodController().hasComposition()) { 1902 if (toLocalFrame(focusedFrame.get())->inputMethodController().hasCom position()) {
1894 if (m_autofillClient) 1903 if (m_autofillClient)
1895 m_autofillClient->setIgnoreTextChanges(true); 1904 m_autofillClient->setIgnoreTextChanges(true);
1896 1905
1897 focusedFrame->inputMethodController().confirmComposition(); 1906 toLocalFrame(focusedFrame.get())->inputMethodController().confir mComposition();
1898 1907
1899 if (m_autofillClient) 1908 if (m_autofillClient)
1900 m_autofillClient->setIgnoreTextChanges(false); 1909 m_autofillClient->setIgnoreTextChanges(false);
1901 } 1910 }
1902 m_imeAcceptEvents = false; 1911 m_imeAcceptEvents = false;
1903 } 1912 }
1904 } 1913 }
1905 } 1914 }
1906 1915
1907 bool WebViewImpl::setComposition( 1916 bool WebViewImpl::setComposition(
1908 const WebString& text, 1917 const WebString& text,
1909 const WebVector<WebCompositionUnderline>& underlines, 1918 const WebVector<WebCompositionUnderline>& underlines,
1910 int selectionStart, 1919 int selectionStart,
1911 int selectionEnd) 1920 int selectionEnd)
1912 { 1921 {
1913 LocalFrame* focused = focusedWebCoreFrame(); 1922 LocalFrame* focused = toLocalFrame(focusedWebCoreFrame());
1914 if (!focused || !m_imeAcceptEvents) 1923 if (!focused || !m_imeAcceptEvents)
1915 return false; 1924 return false;
1916 1925
1917 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) 1926 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
1918 return plugin->setComposition(text, underlines, selectionStart, selectio nEnd); 1927 return plugin->setComposition(text, underlines, selectionStart, selectio nEnd);
1919 1928
1920 // The input focus has been moved to another WebWidget object. 1929 // The input focus has been moved to another WebWidget object.
1921 // We should use this |editor| object only to complete the ongoing 1930 // We should use this |editor| object only to complete the ongoing
1922 // composition. 1931 // composition.
1923 InputMethodController& inputMethodController = focused->inputMethodControlle r(); 1932 InputMethodController& inputMethodController = focused->inputMethodControlle r();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 return confirmComposition(WebString(), selectionBehavior); 1978 return confirmComposition(WebString(), selectionBehavior);
1970 } 1979 }
1971 1980
1972 bool WebViewImpl::confirmComposition(const WebString& text) 1981 bool WebViewImpl::confirmComposition(const WebString& text)
1973 { 1982 {
1974 return confirmComposition(text, DoNotKeepSelection); 1983 return confirmComposition(text, DoNotKeepSelection);
1975 } 1984 }
1976 1985
1977 bool WebViewImpl::confirmComposition(const WebString& text, ConfirmCompositionBe havior selectionBehavior) 1986 bool WebViewImpl::confirmComposition(const WebString& text, ConfirmCompositionBe havior selectionBehavior)
1978 { 1987 {
1979 LocalFrame* focused = focusedWebCoreFrame(); 1988 LocalFrame* focused = toLocalFrame(focusedWebCoreFrame());
1980 if (!focused || !m_imeAcceptEvents) 1989 if (!focused || !m_imeAcceptEvents)
1981 return false; 1990 return false;
1982 1991
1983 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) 1992 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
1984 return plugin->confirmComposition(text, selectionBehavior); 1993 return plugin->confirmComposition(text, selectionBehavior);
1985 1994
1986 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection); 1995 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection);
1987 } 1996 }
1988 1997
1989 bool WebViewImpl::compositionRange(size_t* location, size_t* length) 1998 bool WebViewImpl::compositionRange(size_t* location, size_t* length)
1990 { 1999 {
1991 LocalFrame* focused = focusedWebCoreFrame(); 2000 LocalFrame* focused = toLocalFrame(focusedWebCoreFrame());
1992 if (!focused || !m_imeAcceptEvents) 2001 if (!focused || !m_imeAcceptEvents)
1993 return false; 2002 return false;
1994 2003
1995 RefPtr<Range> range = focused->inputMethodController().compositionRange(); 2004 RefPtr<Range> range = focused->inputMethodController().compositionRange();
1996 if (!range) 2005 if (!range)
1997 return false; 2006 return false;
1998 2007
1999 Element* editable = focused->selection().rootEditableElementOrDocumentElemen t(); 2008 Element* editable = focused->selection().rootEditableElementOrDocumentElemen t();
2000 ASSERT(editable); 2009 ASSERT(editable);
2001 PlainTextRange plainTextRange(PlainTextRange::create(*editable, *range.get() )); 2010 PlainTextRange plainTextRange(PlainTextRange::create(*editable, *range.get() ));
2002 if (plainTextRange.isNull()) 2011 if (plainTextRange.isNull())
2003 return false; 2012 return false;
2004 *location = plainTextRange.start(); 2013 *location = plainTextRange.start();
2005 *length = plainTextRange.length(); 2014 *length = plainTextRange.length();
2006 return true; 2015 return true;
2007 } 2016 }
2008 2017
2009 WebTextInputInfo WebViewImpl::textInputInfo() 2018 WebTextInputInfo WebViewImpl::textInputInfo()
2010 { 2019 {
2011 WebTextInputInfo info; 2020 WebTextInputInfo info;
2012 2021
2013 LocalFrame* focused = focusedWebCoreFrame(); 2022 LocalFrame* focused = toLocalFrame(focusedWebCoreFrame());
2014 if (!focused) 2023 if (!focused)
2015 return info; 2024 return info;
2016 2025
2017 FrameSelection& selection = focused->selection(); 2026 FrameSelection& selection = focused->selection();
2018 Node* node = selection.selection().rootEditableElement(); 2027 Node* node = selection.selection().rootEditableElement();
2019 if (!node) 2028 if (!node)
2020 return info; 2029 return info;
2021 2030
2022 info.inputMode = inputModeOfFocusedElement(); 2031 info.inputMode = inputModeOfFocusedElement();
2023 2032
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 if (isHTMLTextAreaElement(*element)) { 2138 if (isHTMLTextAreaElement(*element)) {
2130 const HTMLTextAreaElement& textarea = toHTMLTextAreaElement(*element); 2139 const HTMLTextAreaElement& textarea = toHTMLTextAreaElement(*element);
2131 return textarea.fastGetAttribute(HTMLNames::inputmodeAttr).lower(); 2140 return textarea.fastGetAttribute(HTMLNames::inputmodeAttr).lower();
2132 } 2141 }
2133 2142
2134 return WebString(); 2143 return WebString();
2135 } 2144 }
2136 2145
2137 bool WebViewImpl::selectionBounds(WebRect& anchor, WebRect& focus) const 2146 bool WebViewImpl::selectionBounds(WebRect& anchor, WebRect& focus) const
2138 { 2147 {
2139 const LocalFrame* frame = focusedWebCoreFrame(); 2148 const LocalFrame* frame = toLocalFrame(focusedWebCoreFrame());
2140 if (!frame) 2149 if (!frame)
2141 return false; 2150 return false;
2142 FrameSelection& selection = frame->selection(); 2151 FrameSelection& selection = frame->selection();
2143 2152
2144 if (selection.isCaret()) { 2153 if (selection.isCaret()) {
2145 anchor = focus = selection.absoluteCaretBounds(); 2154 anchor = focus = selection.absoluteCaretBounds();
2146 } else { 2155 } else {
2147 RefPtr<Range> selectedRange = selection.toNormalizedRange(); 2156 RefPtr<Range> selectedRange = selection.toNormalizedRange();
2148 if (!selectedRange) 2157 if (!selectedRange)
2149 return false; 2158 return false;
(...skipping 23 matching lines...) Expand all
2173 if (!selection.selection().isBaseFirst()) 2182 if (!selection.selection().isBaseFirst())
2174 std::swap(anchor, focus); 2183 std::swap(anchor, focus);
2175 return true; 2184 return true;
2176 } 2185 }
2177 2186
2178 InputMethodContext* WebViewImpl::inputMethodContext() 2187 InputMethodContext* WebViewImpl::inputMethodContext()
2179 { 2188 {
2180 if (!m_imeAcceptEvents) 2189 if (!m_imeAcceptEvents)
2181 return 0; 2190 return 0;
2182 2191
2183 LocalFrame* focusedFrame = focusedWebCoreFrame(); 2192 LocalFrame* focusedFrame = toLocalFrame(focusedWebCoreFrame());
2184 if (!focusedFrame) 2193 if (!focusedFrame)
2185 return 0; 2194 return 0;
2186 2195
2187 Element* target = focusedFrame->document()->focusedElement(); 2196 Element* target = focusedFrame->document()->focusedElement();
2188 if (target && target->hasInputMethodContext()) 2197 if (target && target->hasInputMethodContext())
2189 return &target->inputMethodContext(); 2198 return &target->inputMethodContext();
2190 2199
2191 return 0; 2200 return 0;
2192 } 2201 }
2193 2202
(...skipping 18 matching lines...) Expand all
2212 } 2221 }
2213 2222
2214 void WebViewImpl::didHideCandidateWindow() 2223 void WebViewImpl::didHideCandidateWindow()
2215 { 2224 {
2216 if (InputMethodContext* context = inputMethodContext()) 2225 if (InputMethodContext* context = inputMethodContext())
2217 context->dispatchCandidateWindowHideEvent(); 2226 context->dispatchCandidateWindowHideEvent();
2218 } 2227 }
2219 2228
2220 bool WebViewImpl::selectionTextDirection(WebTextDirection& start, WebTextDirecti on& end) const 2229 bool WebViewImpl::selectionTextDirection(WebTextDirection& start, WebTextDirecti on& end) const
2221 { 2230 {
2222 const LocalFrame* frame = focusedWebCoreFrame(); 2231 const LocalFrame* frame = toLocalFrame(focusedWebCoreFrame());
2223 if (!frame) 2232 if (!frame)
2224 return false; 2233 return false;
2225 FrameSelection& selection = frame->selection(); 2234 FrameSelection& selection = frame->selection();
2226 if (!selection.toNormalizedRange()) 2235 if (!selection.toNormalizedRange())
2227 return false; 2236 return false;
2228 start = selection.start().primaryDirection() == RTL ? WebTextDirectionRightT oLeft : WebTextDirectionLeftToRight; 2237 start = selection.start().primaryDirection() == RTL ? WebTextDirectionRightT oLeft : WebTextDirectionLeftToRight;
2229 end = selection.end().primaryDirection() == RTL ? WebTextDirectionRightToLef t : WebTextDirectionLeftToRight; 2238 end = selection.end().primaryDirection() == RTL ? WebTextDirectionRightToLef t : WebTextDirectionLeftToRight;
2230 return true; 2239 return true;
2231 } 2240 }
2232 2241
2233 bool WebViewImpl::isSelectionAnchorFirst() const 2242 bool WebViewImpl::isSelectionAnchorFirst() const
2234 { 2243 {
2235 if (const LocalFrame* frame = focusedWebCoreFrame()) 2244 if (const LocalFrame* frame = toLocalFrame(focusedWebCoreFrame()))
2236 return frame->selection().selection().isBaseFirst(); 2245 return frame->selection().selection().isBaseFirst();
2237 return false; 2246 return false;
2238 } 2247 }
2239 2248
2240 WebVector<WebCompositionUnderline> WebViewImpl::compositionUnderlines() const 2249 WebVector<WebCompositionUnderline> WebViewImpl::compositionUnderlines() const
2241 { 2250 {
2242 const LocalFrame* focused = focusedWebCoreFrame(); 2251 const LocalFrame* focused = toLocalFrame(focusedWebCoreFrame());
2243 if (!focused) 2252 if (!focused)
2244 return WebVector<WebCompositionUnderline>(); 2253 return WebVector<WebCompositionUnderline>();
2245 const Vector<CompositionUnderline>& underlines = focused->inputMethodControl ler().customCompositionUnderlines(); 2254 const Vector<CompositionUnderline>& underlines = focused->inputMethodControl ler().customCompositionUnderlines();
2246 WebVector<WebCompositionUnderline> results(underlines.size()); 2255 WebVector<WebCompositionUnderline> results(underlines.size());
2247 for (size_t index = 0; index < underlines.size(); ++index) { 2256 for (size_t index = 0; index < underlines.size(); ++index) {
2248 CompositionUnderline underline = underlines[index]; 2257 CompositionUnderline underline = underlines[index];
2249 results[index] = WebCompositionUnderline(underline.startOffset, underlin e.endOffset, static_cast<WebColor>(underline.color.rgb()), underline.thick); 2258 results[index] = WebCompositionUnderline(underline.startOffset, underlin e.endOffset, static_cast<WebColor>(underline.color.rgb()), underline.thick);
2250 } 2259 }
2251 return results; 2260 return results;
2252 } 2261 }
2253 2262
2254 WebColor WebViewImpl::backgroundColor() const 2263 WebColor WebViewImpl::backgroundColor() const
2255 { 2264 {
2256 if (isTransparent()) 2265 if (isTransparent())
2257 return Color::transparent; 2266 return Color::transparent;
2258 if (!m_page) 2267 if (!m_page)
2259 return m_baseBackgroundColor; 2268 return m_baseBackgroundColor;
2260 if (!m_page->mainFrame()) 2269 if (!m_page->mainFrame())
2261 return m_baseBackgroundColor; 2270 return m_baseBackgroundColor;
2262 FrameView* view = m_page->mainFrame()->view(); 2271 FrameView* view = m_page->mainFrame()->view();
2263 return view->documentBackgroundColor().rgb(); 2272 return view->documentBackgroundColor().rgb();
2264 } 2273 }
2265 2274
2266 bool WebViewImpl::caretOrSelectionRange(size_t* location, size_t* length) 2275 bool WebViewImpl::caretOrSelectionRange(size_t* location, size_t* length)
2267 { 2276 {
2268 const LocalFrame* focused = focusedWebCoreFrame(); 2277 const LocalFrame* focused = toLocalFrame(focusedWebCoreFrame());
2269 if (!focused) 2278 if (!focused)
2270 return false; 2279 return false;
2271 2280
2272 PlainTextRange selectionOffsets = focused->inputMethodController().getSelect ionOffsets(); 2281 PlainTextRange selectionOffsets = focused->inputMethodController().getSelect ionOffsets();
2273 if (selectionOffsets.isNull()) 2282 if (selectionOffsets.isNull())
2274 return false; 2283 return false;
2275 2284
2276 *location = selectionOffsets.start(); 2285 *location = selectionOffsets.start();
2277 *length = selectionOffsets.length(); 2286 *length = selectionOffsets.length();
2278 return true; 2287 return true;
2279 } 2288 }
2280 2289
2281 void WebViewImpl::setTextDirection(WebTextDirection direction) 2290 void WebViewImpl::setTextDirection(WebTextDirection direction)
2282 { 2291 {
2283 // The Editor::setBaseWritingDirection() function checks if we can change 2292 // The Editor::setBaseWritingDirection() function checks if we can change
2284 // the text direction of the selected node and updates its DOM "dir" 2293 // the text direction of the selected node and updates its DOM "dir"
2285 // attribute and its CSS "direction" property. 2294 // attribute and its CSS "direction" property.
2286 // So, we just call the function as Safari does. 2295 // So, we just call the function as Safari does.
2287 const LocalFrame* focused = focusedWebCoreFrame(); 2296 const LocalFrame* focused = toLocalFrame(focusedWebCoreFrame());
2288 if (!focused) 2297 if (!focused)
2289 return; 2298 return;
2290 2299
2291 Editor& editor = focused->editor(); 2300 Editor& editor = focused->editor();
2292 if (!editor.canEdit()) 2301 if (!editor.canEdit())
2293 return; 2302 return;
2294 2303
2295 switch (direction) { 2304 switch (direction) {
2296 case WebTextDirectionDefault: 2305 case WebTextDirectionDefault:
2297 editor.setBaseWritingDirection(NaturalWritingDirection); 2306 editor.setBaseWritingDirection(NaturalWritingDirection);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2414 { 2423 {
2415 if (!relativeToFrame) 2424 if (!relativeToFrame)
2416 relativeToFrame = mainFrame(); 2425 relativeToFrame = mainFrame();
2417 LocalFrame* frame = toWebFrameImpl(relativeToFrame)->frame(); 2426 LocalFrame* frame = toWebFrameImpl(relativeToFrame)->frame();
2418 frame = frame->tree().find(name); 2427 frame = frame->tree().find(name);
2419 return WebFrameImpl::fromFrame(frame); 2428 return WebFrameImpl::fromFrame(frame);
2420 } 2429 }
2421 2430
2422 WebFrame* WebViewImpl::focusedFrame() 2431 WebFrame* WebViewImpl::focusedFrame()
2423 { 2432 {
2424 return WebFrameImpl::fromFrame(focusedWebCoreFrame()); 2433 return WebFrameImpl::fromFrame(toLocalFrame(focusedWebCoreFrame()));
2425 } 2434 }
2426 2435
2427 void WebViewImpl::setFocusedFrame(WebFrame* frame) 2436 void WebViewImpl::setFocusedFrame(WebFrame* frame)
2428 { 2437 {
2429 if (!frame) { 2438 if (!frame) {
2430 // Clears the focused frame if any. 2439 // Clears the focused frame if any.
2431 if (LocalFrame* focusedFrame = focusedWebCoreFrame()) 2440 Frame* focusedFrame = focusedWebCoreFrame();
2432 focusedFrame->selection().setFocused(false); 2441 if (focusedFrame && focusedFrame->isLocalFrame())
2442 toLocalFrame(focusedFrame)->selection().setFocused(false);
2433 return; 2443 return;
2434 } 2444 }
2435 LocalFrame* webcoreFrame = toWebFrameImpl(frame)->frame(); 2445 LocalFrame* webcoreFrame = toWebFrameImpl(frame)->frame();
2436 webcoreFrame->page()->focusController().setFocusedFrame(webcoreFrame); 2446 webcoreFrame->page()->focusController().setFocusedFrame(webcoreFrame);
2437 } 2447 }
2438 2448
2439 void WebViewImpl::setInitialFocus(bool reverse) 2449 void WebViewImpl::setInitialFocus(bool reverse)
2440 { 2450 {
2441 if (!m_page) 2451 if (!m_page)
2442 return; 2452 return;
2443 LocalFrame* frame = page()->focusController().focusedOrMainFrame(); 2453 Frame* frame = page()->focusController().focusedOrMainFrame();
2444 if (Document* document = frame->document()) 2454 if (frame->isLocalFrame()) {
2445 document->setFocusedElement(nullptr); 2455 if (Document* document = toLocalFrame(frame)->document())
2456 document->setFocusedElement(nullptr);
2457 }
2446 page()->focusController().setInitialFocus(reverse ? FocusTypeBackward : Focu sTypeForward); 2458 page()->focusController().setInitialFocus(reverse ? FocusTypeBackward : Focu sTypeForward);
2447 } 2459 }
2448 2460
2449 void WebViewImpl::clearFocusedElement() 2461 void WebViewImpl::clearFocusedElement()
2450 { 2462 {
2451 RefPtr<LocalFrame> frame = focusedWebCoreFrame(); 2463 RefPtr<Frame> frame = focusedWebCoreFrame();
2452 if (!frame) 2464 if (!frame || !frame->isLocalFrame())
2453 return; 2465 return;
2454 2466
2455 RefPtr<Document> document = frame->document(); 2467 LocalFrame* localFrame = toLocalFrame(frame.get());
2468
2469 RefPtr<Document> document = localFrame->document();
2456 if (!document) 2470 if (!document)
2457 return; 2471 return;
2458 2472
2459 RefPtr<Element> oldFocusedElement = document->focusedElement(); 2473 RefPtr<Element> oldFocusedElement = document->focusedElement();
2460 2474
2461 // Clear the focused node. 2475 // Clear the focused node.
2462 document->setFocusedElement(nullptr); 2476 document->setFocusedElement(nullptr);
2463 2477
2464 if (!oldFocusedElement) 2478 if (!oldFocusedElement)
2465 return; 2479 return;
2466 2480
2467 // If a text field has focus, we need to make sure the selection controller 2481 // If a text field has focus, we need to make sure the selection controller
2468 // knows to remove selection from it. Otherwise, the text field is still 2482 // knows to remove selection from it. Otherwise, the text field is still
2469 // processing keyboard events even though focus has been moved to the page a nd 2483 // processing keyboard events even though focus has been moved to the page a nd
2470 // keystrokes get eaten as a result. 2484 // keystrokes get eaten as a result.
2471 if (oldFocusedElement->isContentEditable() || oldFocusedElement->isTextFormC ontrol()) 2485 if (oldFocusedElement->isContentEditable() || oldFocusedElement->isTextFormC ontrol())
2472 frame->selection().clear(); 2486 localFrame->selection().clear();
2473 } 2487 }
2474 2488
2475 void WebViewImpl::scrollFocusedNodeIntoView() 2489 void WebViewImpl::scrollFocusedNodeIntoView()
2476 { 2490 {
2477 if (Element* element = focusedElement()) 2491 if (Element* element = focusedElement())
2478 element->scrollIntoViewIfNeeded(true); 2492 element->scrollIntoViewIfNeeded(true);
2479 } 2493 }
2480 2494
2481 void WebViewImpl::scrollFocusedNodeIntoRect(const WebRect& rect) 2495 void WebViewImpl::scrollFocusedNodeIntoRect(const WebRect& rect)
2482 { 2496 {
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
3298 m_page->contextMenuController().clearContextMenu(); 3312 m_page->contextMenuController().clearContextMenu();
3299 } 3313 }
3300 3314
3301 void WebViewImpl::showContextMenu() 3315 void WebViewImpl::showContextMenu()
3302 { 3316 {
3303 if (!page()) 3317 if (!page())
3304 return; 3318 return;
3305 3319
3306 page()->contextMenuController().clearContextMenu(); 3320 page()->contextMenuController().clearContextMenu();
3307 m_contextMenuAllowed = true; 3321 m_contextMenuAllowed = true;
3308 if (LocalFrame* focusedFrame = page()->focusController().focusedOrMainFrame( )) 3322 if (LocalFrame* focusedFrame = toLocalFrame(page()->focusController().focuse dOrMainFrame()))
3309 focusedFrame->eventHandler().sendContextMenuEventForKey(); 3323 focusedFrame->eventHandler().sendContextMenuEventForKey();
3310 m_contextMenuAllowed = false; 3324 m_contextMenuAllowed = false;
3311 } 3325 }
3312 3326
3313 WebString WebViewImpl::getSmartClipData(WebRect rect) 3327 WebString WebViewImpl::getSmartClipData(WebRect rect)
3314 { 3328 {
3315 LocalFrame* frame = focusedWebCoreFrame(); 3329 LocalFrame* frame = toLocalFrame(focusedWebCoreFrame());
3316 if (!frame) 3330 if (!frame)
3317 return WebString(); 3331 return WebString();
3318 return WebCore::SmartClip(frame).dataForRect(rect).toString(); 3332 return WebCore::SmartClip(frame).dataForRect(rect).toString();
3319 } 3333 }
3320 3334
3321 void WebViewImpl::hidePopups() 3335 void WebViewImpl::hidePopups()
3322 { 3336 {
3323 hideSelectPopup(); 3337 hideSelectPopup();
3324 if (m_pagePopup) 3338 if (m_pagePopup)
3325 closePagePopup(m_pagePopup.get()); 3339 closePagePopup(m_pagePopup.get());
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
3538 3552
3539 NotificationPresenterImpl* WebViewImpl::notificationPresenterImpl() 3553 NotificationPresenterImpl* WebViewImpl::notificationPresenterImpl()
3540 { 3554 {
3541 if (!m_notificationPresenter.isInitialized() && m_client) 3555 if (!m_notificationPresenter.isInitialized() && m_client)
3542 m_notificationPresenter.initialize(m_client->notificationPresenter()); 3556 m_notificationPresenter.initialize(m_client->notificationPresenter());
3543 return &m_notificationPresenter; 3557 return &m_notificationPresenter;
3544 } 3558 }
3545 3559
3546 Element* WebViewImpl::focusedElement() const 3560 Element* WebViewImpl::focusedElement() const
3547 { 3561 {
3548 LocalFrame* frame = m_page->focusController().focusedFrame(); 3562 Frame* frame = m_page->focusController().focusedFrame();
3549 if (!frame) 3563 if (!frame || !frame->isLocalFrame())
3550 return 0; 3564 return 0;
3551 3565
3552 Document* document = frame->document(); 3566 Document* document = toLocalFrame(frame)->document();
3553 if (!document) 3567 if (!document)
3554 return 0; 3568 return 0;
3555 3569
3556 return document->focusedElement(); 3570 return document->focusedElement();
3557 } 3571 }
3558 3572
3559 HitTestResult WebViewImpl::hitTestResultForWindowPos(const IntPoint& pos) 3573 HitTestResult WebViewImpl::hitTestResultForWindowPos(const IntPoint& pos)
3560 { 3574 {
3561 IntPoint docPoint(m_page->mainFrame()->view()->windowToContents(pos)); 3575 IntPoint docPoint(m_page->mainFrame()->view()->windowToContents(pos));
3562 return m_page->mainFrame()->eventHandler().hitTestResultAtPoint(docPoint, Hi tTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::ConfusingAndOf tenMisusedDisallowShadowContent); 3576 return m_page->mainFrame()->eventHandler().hitTestResultAtPoint(docPoint, Hi tTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::ConfusingAndOf tenMisusedDisallowShadowContent);
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
3963 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); 3977 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints();
3964 3978
3965 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 3979 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
3966 return false; 3980 return false;
3967 3981
3968 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 3982 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
3969 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 3983 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
3970 } 3984 }
3971 3985
3972 } // namespace blink 3986 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698