#include "config.h"
#include "WebViewImpl.h"
#include "AutoFillPopupMenuClient.h"
#include "AutocompletePopupMenuClient.h"
#include "AXObjectCache.h"
#include "Chrome.h"
#include "ContextMenu.h"
#include "ContextMenuController.h"
#include "ContextMenuItem.h"
#include "CSSStyleSelector.h"
#include "CSSValueKeywords.h"
#include "Cursor.h"
#include "Document.h"
#include "DocumentLoader.h"
#include "DOMUtilitiesPrivate.h"
#include "DragController.h"
#include "DragData.h"
#include "Editor.h"
#include "EventHandler.h"
#include "FocusController.h"
#include "FontDescription.h"
#include "FrameLoader.h"
#include "FrameTree.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "HitTestResult.h"
#include "HTMLInputElement.h"
#include "HTMLMediaElement.h"
#include "HTMLNames.h"
#include "Image.h"
#include "InspectorController.h"
#include "IntRect.h"
#include "KeyboardCodes.h"
#include "KeyboardEvent.h"
#include "MIMETypeRegistry.h"
#include "NodeRenderStyle.h"
#include "Page.h"
#include "PageGroup.h"
#include "PageGroupLoadDeferrer.h"
#include "Pasteboard.h"
#include "PlatformContextSkia.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformMouseEvent.h"
#include "PlatformWheelEvent.h"
#include "PluginInfoStore.h"
#include "PopupMenuChromium.h"
#include "PopupMenuClient.h"
#include "ProgressTracker.h"
#include "RenderView.h"
#include "ResourceHandle.h"
#include "SecurityOrigin.h"
#include "SelectionController.h"
#include "Settings.h"
#include "TypingCommand.h"
#include "WebAccessibilityObject.h"
#include "WebDevToolsAgentPrivate.h"
#include "WebDragData.h"
#include "WebFrameImpl.h"
#include "WebImage.h"
#include "WebInputEvent.h"
#include "WebInputEventConversion.h"
#include "WebMediaPlayerAction.h"
#include "WebNode.h"
#include "WebPoint.h"
#include "WebPopupMenuImpl.h"
#include "WebRect.h"
#include "WebSettingsImpl.h"
#include "WebString.h"
#include "WebVector.h"
#include "WebViewClient.h"
#if OS(WINDOWS)
#include "RenderThemeChromiumWin.h"
#else
#if OS(LINUX)
#include "RenderThemeChromiumLinux.h"
#endif
#include "RenderTheme.h"
#endif
#undef pow
#include <cmath> // for std::pow
using namespace WebCore;
namespace WebKit {
static const double textSizeMultiplierRatio = 1.2;
static const double minTextSizeMultiplier = 0.5;
static const double maxTextSizeMultiplier = 3.0;
const char* pageGroupName = "default";
static PageGroupLoadDeferrer* pageGroupLoadDeferrer;
#define COMPILE_ASSERT_MATCHING_ENUM(coreName) \
COMPILE_ASSERT(int(coreName) == int(Web##coreName), dummy##coreName)
COMPILE_ASSERT_MATCHING_ENUM(DragOperationNone);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete);
COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery);
static const PopupContainerSettings suggestionsPopupSettings = {
false, false, true, true, PopupContainerSettings::DOMElementDirection,
};
WebView* WebView::create(WebViewClient* client)
{
return new WebViewImpl(client);
}
void WebView::updateVisitedLinkState(unsigned long long linkHash)
{
Page::visitedStateChanged(PageGroup::pageGroup(pageGroupName), linkHash);
}
void WebView::resetVisitedLinkState()
{
Page::allVisitedStateChanged(PageGroup::pageGroup(pageGroupName));
}
void WebView::willEnterModalLoop()
{
ASSERT(!pageGroupLoadDeferrer);
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
ASSERT(pageGroup);
if (pageGroup->pages().isEmpty())
return;
pageGroupLoadDeferrer = new PageGroupLoadDeferrer(*pageGroup->pages().begin(), true);
}
void WebView::didExitModalLoop()
{
delete pageGroupLoadDeferrer;
pageGroupLoadDeferrer = 0;
}
void WebViewImpl::initializeMainFrame(WebFrameClient* frameClient)
{
RefPtr<WebFrameImpl> frame = WebFrameImpl::create(frameClient);
frame->initializeAsMainFrame(this);
SecurityOrigin::setLocalLoadPolicy(SecurityOrigin::AllowLocalLoadsForLocalOnly);
}
WebViewImpl::WebViewImpl(WebViewClient* client)
: m_client(client)
, m_backForwardListClientImpl(this)
, m_chromeClientImpl(this)
, m_contextMenuClientImpl(this)
, m_dragClientImpl(this)
, m_editorClientImpl(this)
, m_inspectorClientImpl(this)
, m_observedNewNavigation(false)
#ifndef NDEBUG
, m_newNavigationLoader(0)
#endif
, m_zoomLevel(0)
, m_contextMenuAllowed(false)
, m_doingDragAndDrop(false)
, m_ignoreInputEvents(false)
, m_suppressNextKeypressEvent(false)
, m_initialNavigationPolicy(WebNavigationPolicyIgnore)
, m_imeAcceptEvents(true)
, m_dragTargetDispatch(false)
, m_dragIdentity(0)
, m_dropEffect(DropEffectDefault)
, m_operationsAllowed(WebDragOperationNone)
, m_dragOperation(WebDragOperationNone)
, m_suggestionsPopupShowing(false)
, m_suggestionsPopupClient(0)
, m_suggestionsPopup(0)
, m_isTransparent(false)
, m_tabsToLinks(false)
, m_haveMouseCapture(false)
#if USE(ACCELERATED_COMPOSITING)
, m_layerRenderer(0)
, m_isAcceleratedCompositingActive(false)
#endif
{
WTF::initializeThreading();
WTF::initializeMainThread();
m_lastMousePosition = WebPoint(-1, -1);
m_page.set(new Page(&m_chromeClientImpl,
&m_contextMenuClientImpl,
&m_editorClientImpl,
&m_dragClientImpl,
&m_inspectorClientImpl,
0,
0));
m_page->backForwardList()->setClient(&m_backForwardListClientImpl);
m_page->setGroupName(pageGroupName);
}
WebViewImpl::~WebViewImpl()
{
ASSERT(!m_page);
}
RenderTheme* WebViewImpl::theme() const
{
return m_page.get() ? m_page->theme() : RenderTheme::defaultTheme().get();
}
WebFrameImpl* WebViewImpl::mainFrameImpl()
{
return m_page.get() ? WebFrameImpl::fromFrame(m_page->mainFrame()) : 0;
}
bool WebViewImpl::tabKeyCyclesThroughElements() const
{
ASSERT(m_page.get());
return m_page->tabKeyCyclesThroughElements();
}
void WebViewImpl::setTabKeyCyclesThroughElements(bool value)
{
if (m_page)
m_page->setTabKeyCyclesThroughElements(value);
}
void WebViewImpl::mouseMove(const WebMouseEvent& event)
{
if (!mainFrameImpl() || !mainFrameImpl()->frameView())
return;
m_lastMousePosition = WebPoint(event.x, event.y);
mainFrameImpl()->frame()->eventHandler()->mouseMoved(
PlatformMouseEventBuilder(mainFrameImpl()->frameView(), event));
}
void WebViewImpl::mouseLeave(const WebMouseEvent& event)
{
if (!mainFrameImpl() || !mainFrameImpl()->frameView())
return;
m_client->setMouseOverURL(WebURL());
mainFrameImpl()->frame()->eventHandler()->handleMouseMoveEvent(
PlatformMouseEventBuilder(mainFrameImpl()->frameView(), event));
}
void WebViewImpl::mouseDown(const WebMouseEvent& event)
{
if (!mainFrameImpl() || !mainFrameImpl()->frameView())
return;
RefPtr<WebCore::PopupContainer> selectPopup;
if (event.button == WebMouseEvent::ButtonLeft) {
selectPopup = m_selectPopup;
hideSelectPopup();
ASSERT(!m_selectPopup);
}
m_lastMouseDownPoint = WebPoint(event.x, event.y);
m_haveMouseCapture = true;
RefPtr<Node> clickedNode;
if (event.button == WebMouseEvent::ButtonLeft) {
RefPtr<Node> focusedNode = focusedWebCoreNode();
if (focusedNode.get() && toHTMLInputElement(focusedNode.get())) {
IntPoint point(event.x, event.y);
point = m_page->mainFrame()->view()->windowToContents(point);
HitTestResult result(point);
result = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(point, false);
if (result.innerNonSharedNode() == focusedNode) {
clickedNode = focusedNode;
}
}
}
mainFrameImpl()->frame()->loader()->resetMultipleFormSubmissionProtection();
mainFrameImpl()->frame()->eventHandler()->handleMousePressEvent(
PlatformMouseEventBuilder(mainFrameImpl()->frameView(), event));
if (clickedNode.get() && clickedNode == focusedWebCoreNode()) {
static_cast<EditorClientImpl*>(m_page->editorClient())->
showFormAutofillForNode(clickedNode.get());
}
if (m_selectPopup && m_selectPopup == selectPopup) {
hideSelectPopup();
}
#if OS(DARWIN)
if (event.button == WebMouseEvent::ButtonRight
|| (event.button == WebMouseEvent::ButtonLeft
&& event.modifiers & WebMouseEvent::ControlKey))
mouseContextMenu(event);
#elif OS(LINUX)
if (event.button == WebMouseEvent::ButtonRight)
mouseContextMenu(event);
#endif
}
void WebViewImpl::mouseContextMenu(const WebMouseEvent& event)
{
if (!mainFrameImpl() || !mainFrameImpl()->frameView())
return;
m_page->contextMenuController()->clearContextMenu();
PlatformMouseEventBuilder pme(mainFrameImpl()->frameView(), event);
HitTestResult result = hitTestResultForWindowPos(pme.pos());
Frame* targetFrame;
if (result.innerNonSharedNode())
targetFrame = result.innerNonSharedNode()->document()->frame();
else
targetFrame = m_page->focusController()->focusedOrMainFrame();
#if OS(WINDOWS)
targetFrame->view()->setCursor(pointerCursor());
#endif
m_contextMenuAllowed = true;
targetFrame->eventHandler()->sendContextMenuEvent(pme);
m_contextMenuAllowed = false;
}
void WebViewImpl::mouseUp(const WebMouseEvent& event)
{
if (!mainFrameImpl() || !mainFrameImpl()->frameView())
return;
#if OS(LINUX)
if (event.button == WebMouseEvent::ButtonMiddle) {
Frame* focused = focusedWebCoreFrame();
FrameView* view = m_page->mainFrame()->view();
IntPoint clickPoint(m_lastMouseDownPoint.x, m_lastMouseDownPoint.y);
IntPoint contentPoint = view->windowToContents(clickPoint);
HitTestResult hitTestResult = focused->eventHandler()->hitTestResultAtPoint(contentPoint, false, false, ShouldHitTestScrollbars);
if (!hitTestResult.scrollbar() && !hitTestResult.isLiveLink() && focused && !view->scrollbarAtPoint(clickPoint)) {
Editor* editor = focused->editor();
Pasteboard* pasteboard = Pasteboard::generalPasteboard();
bool oldSelectionMode = pasteboard->isSelectionMode();
pasteboard->setSelectionMode(true);
editor->command(AtomicString("Paste")).execute();
pasteboard->setSelectionMode(oldSelectionMode);
}
}
#endif
mainFrameImpl()->frame()->eventHandler()->handleMouseReleaseEvent(
PlatformMouseEventBuilder(mainFrameImpl()->frameView(), event));
#if OS(WINDOWS)
if (event.button == WebMouseEvent::ButtonRight)
mouseContextMenu(event);
#endif
}
void WebViewImpl::mouseWheel(const WebMouseWheelEvent& event)
{
PlatformWheelEventBuilder platformEvent(mainFrameImpl()->frameView(), event);
mainFrameImpl()->frame()->eventHandler()->handleWheelEvent(platformEvent);
}
bool WebViewImpl::keyEvent(const WebKeyboardEvent& event)
{
ASSERT((event.type == WebInputEvent::RawKeyDown)
|| (event.type == WebInputEvent::KeyDown)
|| (event.type == WebInputEvent::KeyUp));
m_suppressNextKeypressEvent = false;
if (selectPopupHandleKeyEvent(event))
return true;
if (autocompleteHandleKeyEvent(event))
return true;
Frame* frame = focusedWebCoreFrame();
if (!frame)
return false;
EventHandler* handler = frame->eventHandler();
if (!handler)
return keyEventDefault(event);
#if OS(WINDOWS) || OS(LINUX)
const WebInputEvent::Type contextMenuTriggeringEventType =
#if OS(WINDOWS)
WebInputEvent::KeyUp;
#elif OS(LINUX)
WebInputEvent::RawKeyDown;
#endif
if (((!event.modifiers && (event.windowsKeyCode == VKEY_APPS))
|| ((event.modifiers == WebInputEvent::ShiftKey) && (event.windowsKeyCode == VKEY_F10)))
&& event.type == contextMenuTriggeringEventType) {
sendContextMenuEvent(event);
return true;
}
#endif
if (event.windowsKeyCode == VKEY_CAPITAL)
handler->capsLockStateMayHaveChanged();
PlatformKeyboardEventBuilder evt(event);
if (handler->keyEvent(evt)) {
if (WebInputEvent::RawKeyDown == event.type) {
Node* node = frame->document()->focusedNode();
if (!node || !node->renderer() || !node->renderer()->isEmbeddedObject())
m_suppressNextKeypressEvent = true;
}
return true;
}
return keyEventDefault(event);
}
bool WebViewImpl::selectPopupHandleKeyEvent(const WebKeyboardEvent& event)
{
if (!m_selectPopup)
return false;
return m_selectPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event));
}
bool WebViewImpl::autocompleteHandleKeyEvent(const WebKeyboardEvent& event)
{
if (!m_suggestionsPopupShowing
|| event.windowsKeyCode == VKEY_HOME
|| event.windowsKeyCode == VKEY_END)
return false;
if (event.windowsKeyCode == VKEY_DELETE
&& m_suggestionsPopup->selectedIndex() != -1) {
Node* node = focusedWebCoreNode();
if (!node || (node->nodeType() != Node::ELEMENT_NODE)) {
ASSERT_NOT_REACHED();
return false;
}
Element* element = static_cast<Element*>(node);
if (!element->hasLocalName(HTMLNames::inputTag)) {
ASSERT_NOT_REACHED();
return false;
}
int selectedIndex = m_suggestionsPopup->selectedIndex();
HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(element);
WebString name = inputElement->name();
WebString value = m_suggestionsPopupClient->itemText(selectedIndex);
m_client->removeAutofillSuggestions(name, value);
m_suggestionsPopupClient->removeSuggestionAtIndex(selectedIndex);
refreshSuggestionsPopup();
return false;
}
if (!m_suggestionsPopup->isInterestedInEventForKey(event.windowsKeyCode))
return false;
if (m_suggestionsPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event))) {
if (WebInputEvent::RawKeyDown == event.type)
m_suppressNextKeypressEvent = true;
return true;
}
return false;
}
bool WebViewImpl::charEvent(const WebKeyboardEvent& event)
{
ASSERT(event.type == WebInputEvent::Char);
bool suppress = m_suppressNextKeypressEvent;
m_suppressNextKeypressEvent = false;
Frame* frame = focusedWebCoreFrame();
if (!frame)
return suppress;
EventHandler* handler = frame->eventHandler();
if (!handler)
return suppress || keyEventDefault(event);
PlatformKeyboardEventBuilder evt(event);
if (!evt.isCharacterKey())
return true;
if (handler->handleAccessKey(evt))
return true;
if (evt.isSystemKey())
return false;
if (!suppress && !handler->keyEvent(evt))
return keyEventDefault(event);
return true;
}
#if ENABLE(TOUCH_EVENTS)
bool WebViewImpl::touchEvent(const WebTouchEvent& event)
{
if (!mainFrameImpl() || !mainFrameImpl()->frameView())
return false;
PlatformTouchEventBuilder touchEventBuilder(mainFrameImpl()->frameView(), event);
return mainFrameImpl()->frame()->eventHandler()->handleTouchEvent(touchEventBuilder);
}
#endif
#if OS(WINDOWS) || OS(LINUX)
bool WebViewImpl::sendContextMenuEvent(const WebKeyboardEvent& event)
{
static const int kContextMenuMargin = 1;
Frame* mainFrameImpl = page()->mainFrame();
FrameView* view = mainFrameImpl->view();
if (!view)
return false;
IntPoint coords(-1, -1);
#if OS(WINDOWS)
int rightAligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT);
#else
int rightAligned = 0;
#endif
IntPoint location;
Frame* focusedFrame = page()->focusController()->focusedOrMainFrame();
Node* focusedNode = focusedFrame->document()->focusedNode();
Position start = mainFrameImpl->selection()->selection().start();
if (focusedFrame->editor() && focusedFrame->editor()->canEdit() && start.node()) {
RenderObject* renderer = start.node()->renderer();
if (!renderer)
return false;
RefPtr<Range> selection = mainFrameImpl->selection()->toNormalizedRange();
IntRect firstRect = mainFrameImpl->firstRectForRange(selection.get());
int x = rightAligned ? firstRect.right() : firstRect.x();
location = IntPoint(x, firstRect.bottom());
} else if (focusedNode)
location = focusedNode->getRect().bottomLeft();
else {
location = IntPoint(
rightAligned ? view->contentsWidth() - kContextMenuMargin : kContextMenuMargin,
kContextMenuMargin);
}
location = view->contentsToWindow(location);
coords = location + IntSize(0, -1);
page()->contextMenuController()->clearContextMenu();
focusedFrame->view()->setCursor(pointerCursor());
WebMouseEvent mouseEvent;
mouseEvent.button = WebMouseEvent::ButtonRight;
mouseEvent.x = coords.x();
mouseEvent.y = coords.y();
mouseEvent.type = WebInputEvent::MouseUp;
PlatformMouseEventBuilder platformEvent(view, mouseEvent);
m_contextMenuAllowed = true;
bool handled = focusedFrame->eventHandler()->sendContextMenuEvent(platformEvent);
m_contextMenuAllowed = false;
return handled;
}
#endif
bool WebViewImpl::keyEventDefault(const WebKeyboardEvent& event)
{
Frame* frame = focusedWebCoreFrame();
if (!frame)
return false;
switch (event.type) {
case WebInputEvent::Char:
if (event.windowsKeyCode == VKEY_SPACE) {
int keyCode = ((event.modifiers & WebInputEvent::ShiftKey) ? VKEY_PRIOR : VKEY_NEXT);
return scrollViewWithKeyboard(keyCode, event.modifiers);
}
break;
case WebInputEvent::RawKeyDown:
if (event.modifiers == WebInputEvent::ControlKey) {
switch (event.windowsKeyCode) {
#if !OS(DARWIN)
case 'A':
focusedFrame()->executeCommand(WebString::fromUTF8("SelectAll"));
return true;
case VKEY_INSERT:
case 'C':
focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
return true;
#endif
case VKEY_HOME:
case VKEY_END:
break;
default:
return false;
}
}
if (!event.isSystemKey && !(event.modifiers & WebInputEvent::ShiftKey))
return scrollViewWithKeyboard(event.windowsKeyCode, event.modifiers);
break;
default:
break;
}
return false;
}
bool WebViewImpl::scrollViewWithKeyboard(int keyCode, int modifiers)
{
ScrollDirection scrollDirection;
ScrollGranularity scrollGranularity;
switch (keyCode) {
case VKEY_LEFT:
scrollDirection = ScrollLeft;
scrollGranularity = ScrollByLine;
break;
case VKEY_RIGHT:
scrollDirection = ScrollRight;
scrollGranularity = ScrollByLine;
break;
case VKEY_UP:
scrollDirection = ScrollUp;
scrollGranularity = ScrollByLine;
break;
case VKEY_DOWN:
scrollDirection = ScrollDown;
scrollGranularity = ScrollByLine;
break;
case VKEY_HOME:
scrollDirection = ScrollUp;
scrollGranularity = ScrollByDocument;
break;
case VKEY_END:
scrollDirection = ScrollDown;
scrollGranularity = ScrollByDocument;
break;
case VKEY_PRIOR: scrollDirection = ScrollUp;
scrollGranularity = ScrollByPage;
break;
case VKEY_NEXT: scrollDirection = ScrollDown;
scrollGranularity = ScrollByPage;
break;
default:
return false;
}
return propagateScroll(scrollDirection, scrollGranularity);
}
void WebViewImpl::hideSelectPopup()
{
if (m_selectPopup.get())
m_selectPopup->hidePopup();
}
bool WebViewImpl::propagateScroll(ScrollDirection scrollDirection,
ScrollGranularity scrollGranularity)
{
Frame* frame = focusedWebCoreFrame();
if (!frame)
return false;
bool scrollHandled =
frame->eventHandler()->scrollOverflow(scrollDirection,
scrollGranularity);
Frame* currentFrame = frame;
while (!scrollHandled && currentFrame) {
scrollHandled = currentFrame->view()->scroll(scrollDirection,
scrollGranularity);
currentFrame = currentFrame->tree()->parent();
}
return scrollHandled;
}
void WebViewImpl::popupOpened(WebCore::PopupContainer* popupContainer)
{
if (popupContainer->popupType() == WebCore::PopupContainer::Select) {
ASSERT(!m_selectPopup);
m_selectPopup = popupContainer;
}
}
void WebViewImpl::popupClosed(WebCore::PopupContainer* popupContainer)
{
if (popupContainer->popupType() == WebCore::PopupContainer::Select) {
ASSERT(m_selectPopup.get());
m_selectPopup = 0;
}
}
void WebViewImpl::hideSuggestionsPopup()
{
if (m_suggestionsPopupShowing) {
m_suggestionsPopup->hidePopup();
m_suggestionsPopupShowing = false;
}
}
Frame* WebViewImpl::focusedWebCoreFrame()
{
return m_page.get() ? m_page->focusController()->focusedOrMainFrame() : 0;
}
WebViewImpl* WebViewImpl::fromPage(Page* page)
{
if (!page)
return 0;
return static_cast<ChromeClientImpl*>(page->chrome()->client())->webView();
}
void WebViewImpl::close()
{
RefPtr<WebFrameImpl> mainFrameImpl;
if (m_page.get()) {
if (m_page->mainFrame()) {
mainFrameImpl = WebFrameImpl::fromFrame(m_page->mainFrame());
m_page->mainFrame()->loader()->frameDetached();
}
m_page.clear();
}
if (m_devToolsAgent.get())
m_devToolsAgent.clear();
m_client = 0;
deref(); }
void WebViewImpl::resize(const WebSize& newSize)
{
if (m_size == newSize)
return;
m_size = newSize;
if (mainFrameImpl()->frameView()) {
mainFrameImpl()->frameView()->resize(m_size.width, m_size.height);
mainFrameImpl()->frame()->eventHandler()->sendResizeEvent();
}
if (m_client) {
WebRect damagedRect(0, 0, m_size.width, m_size.height);
m_client->didInvalidateRect(damagedRect);
}
}
void WebViewImpl::layout()
{
WebFrameImpl* webframe = mainFrameImpl();
if (webframe) {
FrameView* view = webframe->frameView();
if (view)
view->setFrameRect(view->frameRect());
webframe->layout();
}
}
void WebViewImpl::paint(WebCanvas* canvas, const WebRect& rect)
{
#if USE(ACCELERATED_COMPOSITING)
if (!isAcceleratedCompositingActive()) {
#endif
WebFrameImpl* webframe = mainFrameImpl();
if (webframe)
webframe->paint(canvas, rect);
#if USE(ACCELERATED_COMPOSITING)
} else {
updateRootLayerContents(rect);
#if PLATFORM(SKIA)
m_layerRenderer->drawLayersInCanvas(static_cast<skia::PlatformCanvas*>(canvas), IntRect(rect));
#elif PLATFORM(CG)
#error "Need to implement CG version"
#endif
}
#endif
}
const WebInputEvent* WebViewImpl::m_currentInputEvent = 0;
bool WebViewImpl::handleInputEvent(const WebInputEvent& inputEvent)
{
if (m_doingDragAndDrop)
return true;
if (m_ignoreInputEvents)
return true;
if (m_haveMouseCapture && WebInputEvent::isMouseEventType(inputEvent.type)) {
if (inputEvent.type == WebInputEvent::MouseUp)
mouseCaptureLost();
Node* node = focusedWebCoreNode();
if (node && node->renderer() && node->renderer()->isEmbeddedObject()) {
AtomicString eventType;
switch (inputEvent.type) {
case WebInputEvent::MouseMove:
eventType = eventNames().mousemoveEvent;
break;
case WebInputEvent::MouseLeave:
eventType = eventNames().mouseoutEvent;
break;
case WebInputEvent::MouseDown:
eventType = eventNames().mousedownEvent;
break;
case WebInputEvent::MouseUp:
eventType = eventNames().mouseupEvent;
break;
default:
ASSERT_NOT_REACHED();
}
node->dispatchMouseEvent(
PlatformMouseEventBuilder(mainFrameImpl()->frameView(), *static_cast<const WebMouseEvent*>(&inputEvent)),
eventType);
return true;
}
}
m_currentInputEvent = &inputEvent;
bool handled = true;
switch (inputEvent.type) {
case WebInputEvent::MouseMove:
mouseMove(*static_cast<const WebMouseEvent*>(&inputEvent));
break;
case WebInputEvent::MouseLeave:
mouseLeave(*static_cast<const WebMouseEvent*>(&inputEvent));
break;
case WebInputEvent::MouseWheel:
mouseWheel(*static_cast<const WebMouseWheelEvent*>(&inputEvent));
break;
case WebInputEvent::MouseDown:
mouseDown(*static_cast<const WebMouseEvent*>(&inputEvent));
break;
case WebInputEvent::MouseUp:
mouseUp(*static_cast<const WebMouseEvent*>(&inputEvent));
break;
case WebInputEvent::RawKeyDown:
case WebInputEvent::KeyDown:
case WebInputEvent::KeyUp:
handled = keyEvent(*static_cast<const WebKeyboardEvent*>(&inputEvent));
break;
case WebInputEvent::Char:
handled = charEvent(*static_cast<const WebKeyboardEvent*>(&inputEvent));
break;
#if ENABLE(TOUCH_EVENTS)
case WebInputEvent::TouchStart:
case WebInputEvent::TouchMove:
case WebInputEvent::TouchEnd:
case WebInputEvent::TouchCancel:
handled = touchEvent(*static_cast<const WebTouchEvent*>(&inputEvent));
break;
#endif
default:
handled = false;
}
m_currentInputEvent = 0;
return handled;
}
void WebViewImpl::mouseCaptureLost()
{
m_haveMouseCapture = false;
}
void WebViewImpl::setFocus(bool enable)
{
m_page->focusController()->setFocused(enable);
if (enable) {
m_page->focusController()->setActive(true);
RefPtr<Frame> focusedFrame = m_page->focusController()->focusedFrame();
if (focusedFrame) {
Node* focusedNode = focusedFrame->document()->focusedNode();
if (focusedNode && focusedNode->isElementNode()
&& focusedFrame->selection()->selection().isNone()) {
Element* element = static_cast<Element*>(focusedNode);
if (element->isTextFormControl())
element->updateFocusAppearance(true);
else if (focusedNode->isContentEditable()) {
Position position(focusedNode, 0,
Position::PositionIsOffsetInAnchor);
focusedFrame->selection()->setSelection(
VisibleSelection(position, SEL_DEFAULT_AFFINITY));
}
}
}
m_imeAcceptEvents = true;
} else {
hideSuggestionsPopup();
hideSelectPopup();
if (!m_page.get())
return;
Frame* frame = m_page->mainFrame();
if (!frame)
return;
RefPtr<Frame> focusedFrame = m_page->focusController()->focusedFrame();
if (focusedFrame.get()) {
Editor* editor = focusedFrame->editor();
if (editor && editor->hasComposition())
editor->confirmComposition();
m_imeAcceptEvents = false;
}
}
}
bool WebViewImpl::handleCompositionEvent(WebCompositionCommand command,
int cursorPosition,
int targetStart,
int targetEnd,
const WebString& imeString)
{
Frame* focused = focusedWebCoreFrame();
if (!focused || !m_imeAcceptEvents)
return false;
Editor* editor = focused->editor();
if (!editor)
return false;
if (!editor->canEdit()) {
if (!editor->hasComposition())
return false;
}
PassRefPtr<Range> range = editor->compositionRange();
if (range) {
const Node* node = range->startPosition().node();
if (!node || !node->isContentEditable())
return false;
}
if (command == WebCompositionCommandDiscard) {
String emptyString;
Vector<CompositionUnderline> emptyUnderlines;
editor->setComposition(emptyString, emptyUnderlines, 0, 0);
} else {
if (targetStart < 0)
targetStart = 0;
if (targetEnd < 0)
targetEnd = static_cast<int>(imeString.length());
String compositionString(imeString);
Vector<CompositionUnderline> underlines(3);
underlines[0].startOffset = 0;
underlines[0].endOffset = targetStart;
underlines[0].thick = true;
underlines[0].color.setRGB(0xd3, 0xd3, 0xd3);
underlines[1].startOffset = targetStart;
underlines[1].endOffset = targetEnd;
underlines[1].thick = true;
underlines[1].color.setRGB(0x00, 0x00, 0x00);
underlines[2].startOffset = targetEnd;
underlines[2].endOffset = static_cast<int>(imeString.length());
underlines[2].thick = true;
underlines[2].color.setRGB(0xd3, 0xd3, 0xd3);
editor->setComposition(compositionString, underlines,
cursorPosition, cursorPosition);
if (command == WebCompositionCommandConfirm)
editor->confirmComposition();
}
return editor->hasComposition();
}
bool WebViewImpl::queryCompositionStatus(bool* enableIME, WebRect* caretRect)
{
const Frame* focused = focusedWebCoreFrame();
if (!focused)
return false;
const Editor* editor = focused->editor();
if (!editor || !editor->canEdit())
return false;
SelectionController* controller = focused->selection();
if (!controller)
return false;
const Node* node = controller->start().node();
if (!node)
return false;
*enableIME = node->shouldUseInputMethod() && !controller->isInPasswordField();
const FrameView* view = node->document()->view();
if (!view)
return false;
*caretRect = view->contentsToWindow(controller->absoluteCaretBounds());
return true;
}
void WebViewImpl::setTextDirection(WebTextDirection direction)
{
const Frame* focused = focusedWebCoreFrame();
if (!focused)
return;
Editor* editor = focused->editor();
if (!editor || !editor->canEdit())
return;
switch (direction) {
case WebTextDirectionDefault:
editor->setBaseWritingDirection(NaturalWritingDirection);
break;
case WebTextDirectionLeftToRight:
editor->setBaseWritingDirection(LeftToRightWritingDirection);
break;
case WebTextDirectionRightToLeft:
editor->setBaseWritingDirection(RightToLeftWritingDirection);
break;
default:
notImplemented();
break;
}
}
bool WebViewImpl::isAcceleratedCompositingActive() const
{
#if USE(ACCELERATED_COMPOSITING)
return m_isAcceleratedCompositingActive;
#else
return false;
#endif
}
WebSettings* WebViewImpl::settings()
{
if (!m_webSettings.get())
m_webSettings.set(new WebSettingsImpl(m_page->settings()));
ASSERT(m_webSettings.get());
return m_webSettings.get();
}
WebString WebViewImpl::pageEncoding() const
{
if (!m_page.get())
return WebString();
return m_page->mainFrame()->loader()->writer()->encoding();
}
void WebViewImpl::setPageEncoding(const WebString& encodingName)
{
if (!m_page.get())
return;
String newEncodingName;
if (!encodingName.isEmpty())
newEncodingName = encodingName;
m_page->mainFrame()->loader()->reloadWithOverrideEncoding(newEncodingName);
}
bool WebViewImpl::dispatchBeforeUnloadEvent()
{
Frame* frame = m_page->mainFrame();
if (!frame)
return true;
return frame->shouldClose();
}
void WebViewImpl::dispatchUnloadEvent()
{
m_page->mainFrame()->loader()->closeURL();
}
WebFrame* WebViewImpl::mainFrame()
{
return mainFrameImpl();
}
WebFrame* WebViewImpl::findFrameByName(
const WebString& name, WebFrame* relativeToFrame)
{
if (!relativeToFrame)
relativeToFrame = mainFrame();
Frame* frame = static_cast<WebFrameImpl*>(relativeToFrame)->frame();
frame = frame->tree()->find(name);
return WebFrameImpl::fromFrame(frame);
}
WebFrame* WebViewImpl::focusedFrame()
{
return WebFrameImpl::fromFrame(focusedWebCoreFrame());
}
void WebViewImpl::setFocusedFrame(WebFrame* frame)
{
if (!frame) {
Frame* frame = focusedWebCoreFrame();
if (frame)
frame->selection()->setFocused(false);
return;
}
WebFrameImpl* frameImpl = static_cast<WebFrameImpl*>(frame);
Frame* webcoreFrame = frameImpl->frame();
webcoreFrame->page()->focusController()->setFocusedFrame(webcoreFrame);
}
void WebViewImpl::setInitialFocus(bool reverse)
{
if (!m_page.get())
return;
WebKeyboardEvent keyboardEvent;
keyboardEvent.type = WebInputEvent::RawKeyDown;
if (reverse)
keyboardEvent.modifiers = WebInputEvent::ShiftKey;
keyboardEvent.windowsKeyCode = 0x09;
PlatformKeyboardEventBuilder platformEvent(keyboardEvent);
RefPtr<KeyboardEvent> webkitEvent = KeyboardEvent::create(platformEvent, 0);
page()->focusController()->setInitialFocus(
reverse ? FocusDirectionBackward : FocusDirectionForward,
webkitEvent.get());
}
void WebViewImpl::clearFocusedNode()
{
if (!m_page.get())
return;
RefPtr<Frame> frame = m_page->mainFrame();
if (!frame.get())
return;
RefPtr<Document> document = frame->document();
if (!document.get())
return;
RefPtr<Node> oldFocusedNode = document->focusedNode();
document->setFocusedNode(0);
if (!oldFocusedNode.get())
return;
if (oldFocusedNode->hasTagName(HTMLNames::textareaTag)
|| (oldFocusedNode->hasTagName(HTMLNames::inputTag)
&& static_cast<HTMLInputElement*>(oldFocusedNode.get())->isTextField())) {
SelectionController* selection = frame->selection();
selection->clear();
}
}
int WebViewImpl::zoomLevel()
{
return m_zoomLevel;
}
int WebViewImpl::setZoomLevel(bool textOnly, int zoomLevel)
{
float zoomFactor = static_cast<float>(
std::max(std::min(std::pow(textSizeMultiplierRatio, zoomLevel),
maxTextSizeMultiplier),
minTextSizeMultiplier));
Frame* frame = mainFrameImpl()->frame();
if (zoomFactor != frame->zoomFactor()) {
m_zoomLevel = zoomLevel;
frame->setZoomFactor(zoomFactor, textOnly ? ZoomTextOnly : ZoomPage);
}
return m_zoomLevel;
}
void WebViewImpl::performMediaPlayerAction(const WebMediaPlayerAction& action,
const WebPoint& location)
{
HitTestResult result =
hitTestResultForWindowPos(location);
RefPtr<Node> node = result.innerNonSharedNode();
if (!node->hasTagName(HTMLNames::videoTag) && !node->hasTagName(HTMLNames::audioTag))
return;
RefPtr<HTMLMediaElement> mediaElement =
static_pointer_cast<HTMLMediaElement>(node);
switch (action.type) {
case WebMediaPlayerAction::Play:
if (action.enable)
mediaElement->play(mediaElement->processingUserGesture());
else
mediaElement->pause(mediaElement->processingUserGesture());
break;
case WebMediaPlayerAction::Mute:
mediaElement->setMuted(action.enable);
break;
case WebMediaPlayerAction::Loop:
mediaElement->setLoop(action.enable);
break;
case WebMediaPlayerAction::Controls:
mediaElement->setControls(action.enable);
break;
default:
ASSERT_NOT_REACHED();
}
}
void WebViewImpl::copyImageAt(const WebPoint& point)
{
if (!m_page.get())
return;
HitTestResult result = hitTestResultForWindowPos(point);
if (result.absoluteImageURL().isEmpty()) {
return;
}
m_page->mainFrame()->editor()->copyImage(result);
}
void WebViewImpl::dragSourceEndedAt(
const WebPoint& clientPoint,
const WebPoint& screenPoint,
WebDragOperation operation)
{
PlatformMouseEvent pme(clientPoint,
screenPoint,
LeftButton, MouseEventMoved, 0, false, false, false,
false, 0);
m_page->mainFrame()->eventHandler()->dragSourceEndedAt(pme,
static_cast<DragOperation>(operation));
}
void WebViewImpl::dragSourceSystemDragEnded()
{
if (m_doingDragAndDrop) {
m_page->dragController()->dragEnded();
m_doingDragAndDrop = false;
}
}
WebDragOperation WebViewImpl::dragTargetDragEnter(
const WebDragData& webDragData, int identity,
const WebPoint& clientPoint,
const WebPoint& screenPoint,
WebDragOperationsMask operationsAllowed)
{
ASSERT(!m_currentDragData.get());
m_currentDragData = webDragData;
m_dragIdentity = identity;
m_operationsAllowed = operationsAllowed;
return dragTargetDragEnterOrOver(clientPoint, screenPoint, DragEnter);
}
WebDragOperation WebViewImpl::dragTargetDragOver(
const WebPoint& clientPoint,
const WebPoint& screenPoint,
WebDragOperationsMask operationsAllowed)
{
m_operationsAllowed = operationsAllowed;
return dragTargetDragEnterOrOver(clientPoint, screenPoint, DragOver);
}
void WebViewImpl::dragTargetDragLeave()
{
ASSERT(m_currentDragData.get());
DragData dragData(
m_currentDragData.get(),
IntPoint(),
IntPoint(),
static_cast<DragOperation>(m_operationsAllowed));
m_dragTargetDispatch = true;
m_page->dragController()->dragExited(&dragData);
m_dragTargetDispatch = false;
m_currentDragData = 0;
m_dropEffect = DropEffectDefault;
m_dragOperation = WebDragOperationNone;
m_dragIdentity = 0;
}
void WebViewImpl::dragTargetDrop(const WebPoint& clientPoint,
const WebPoint& screenPoint)
{
ASSERT(m_currentDragData.get());
if (m_dragOperation == WebDragOperationNone) { dragTargetDragLeave();
return;
}
DragData dragData(
m_currentDragData.get(),
clientPoint,
screenPoint,
static_cast<DragOperation>(m_operationsAllowed));
m_dragTargetDispatch = true;
m_page->dragController()->performDrag(&dragData);
m_dragTargetDispatch = false;
m_currentDragData = 0;
m_dropEffect = DropEffectDefault;
m_dragOperation = WebDragOperationNone;
m_dragIdentity = 0;
}
int WebViewImpl::dragIdentity()
{
if (m_dragTargetDispatch)
return m_dragIdentity;
return 0;
}
WebDragOperation WebViewImpl::dragTargetDragEnterOrOver(const WebPoint& clientPoint, const WebPoint& screenPoint, DragAction dragAction)
{
ASSERT(m_currentDragData.get());
DragData dragData(
m_currentDragData.get(),
clientPoint,
screenPoint,
static_cast<DragOperation>(m_operationsAllowed));
m_dropEffect = DropEffectDefault;
m_dragTargetDispatch = true;
DragOperation effect = dragAction == DragEnter ? m_page->dragController()->dragEntered(&dragData)
: m_page->dragController()->dragUpdated(&dragData);
if (!(effect & dragData.draggingSourceOperationMask()))
effect = DragOperationNone;
m_dragTargetDispatch = false;
if (m_dropEffect != DropEffectDefault) {
m_dragOperation = (m_dropEffect != DropEffectNone) ? WebDragOperationCopy
: WebDragOperationNone;
} else
m_dragOperation = static_cast<WebDragOperation>(effect);
return m_dragOperation;
}
unsigned long WebViewImpl::createUniqueIdentifierForRequest()
{
if (m_page)
return m_page->progress()->createUniqueIdentifier();
return 0;
}
void WebViewImpl::inspectElementAt(const WebPoint& point)
{
if (!m_page.get())
return;
if (point.x == -1 || point.y == -1)
m_page->inspectorController()->inspect(0);
else {
HitTestResult result = hitTestResultForWindowPos(point);
if (!result.innerNonSharedNode())
return;
m_page->inspectorController()->inspect(result.innerNonSharedNode());
}
}
WebString WebViewImpl::inspectorSettings() const
{
return m_inspectorSettings;
}
void WebViewImpl::setInspectorSettings(const WebString& settings)
{
m_inspectorSettings = settings;
}
WebDevToolsAgent* WebViewImpl::devToolsAgent()
{
return m_devToolsAgent.get();
}
void WebViewImpl::setDevToolsAgent(WebDevToolsAgent* devToolsAgent)
{
ASSERT(!m_devToolsAgent.get()); m_devToolsAgent.set(static_cast<WebDevToolsAgentPrivate*>(devToolsAgent));
}
WebAccessibilityObject WebViewImpl::accessibilityObject()
{
if (!mainFrameImpl())
return WebAccessibilityObject();
Document* document = mainFrameImpl()->frame()->document();
return WebAccessibilityObject(
document->axObjectCache()->getOrCreate(document->renderer()));
}
void WebViewImpl::applyAutoFillSuggestions(
const WebNode& node,
const WebVector<WebString>& names,
const WebVector<WebString>& labels,
int defaultSuggestionIndex)
{
ASSERT(names.size() == labels.size());
ASSERT(defaultSuggestionIndex < static_cast<int>(names.size()));
if (names.isEmpty()) {
hideSuggestionsPopup();
return;
}
RefPtr<Node> focusedNode = focusedWebCoreNode();
if (!focusedNode || focusedNode != PassRefPtr<Node>(node)) {
hideSuggestionsPopup();
return;
}
HTMLInputElement* inputElem =
static_cast<HTMLInputElement*>(focusedNode.get());
if (!m_autoFillPopupClient.get())
m_autoFillPopupClient.set(new AutoFillPopupMenuClient);
m_autoFillPopupClient->initialize(inputElem, names, labels,
defaultSuggestionIndex);
if (m_suggestionsPopupClient != m_autoFillPopupClient.get()) {
hideSuggestionsPopup();
m_suggestionsPopupClient = m_autoFillPopupClient.get();
}
if (!m_autoFillPopup.get()) {
m_autoFillPopup = PopupContainer::create(m_suggestionsPopupClient,
PopupContainer::Suggestion,
suggestionsPopupSettings);
}
if (m_suggestionsPopup != m_autoFillPopup.get())
m_suggestionsPopup = m_autoFillPopup.get();
if (m_suggestionsPopupShowing) {
m_autoFillPopupClient->setSuggestions(names, labels);
refreshSuggestionsPopup();
} else {
m_suggestionsPopup->show(focusedNode->getRect(),
focusedNode->ownerDocument()->view(), 0);
m_suggestionsPopupShowing = true;
}
}
void WebViewImpl::applyAutocompleteSuggestions(
const WebNode& node,
const WebVector<WebString>& suggestions,
int defaultSuggestionIndex)
{
ASSERT(defaultSuggestionIndex < static_cast<int>(suggestions.size()));
if (!m_page.get() || suggestions.isEmpty()) {
hideSuggestionsPopup();
return;
}
RefPtr<Node> focusedNode = focusedWebCoreNode();
if (!focusedNode || focusedNode != PassRefPtr<Node>(node)) {
hideSuggestionsPopup();
return;
}
HTMLInputElement* inputElem =
static_cast<HTMLInputElement*>(focusedNode.get());
if (!m_autocompletePopupClient.get())
m_autocompletePopupClient.set(new AutocompletePopupMenuClient);
m_autocompletePopupClient->initialize(inputElem, suggestions,
defaultSuggestionIndex);
if (m_suggestionsPopupClient != m_autocompletePopupClient.get()) {
hideSuggestionsPopup();
m_suggestionsPopupClient = m_autocompletePopupClient.get();
}
if (!m_autocompletePopup.get()) {
m_autocompletePopup = PopupContainer::create(m_suggestionsPopupClient,
PopupContainer::Suggestion,
suggestionsPopupSettings);
}
if (m_suggestionsPopup != m_autocompletePopup.get())
m_suggestionsPopup = m_autocompletePopup.get();
if (m_suggestionsPopupShowing) {
m_autocompletePopupClient->setSuggestions(suggestions);
refreshSuggestionsPopup();
} else {
m_suggestionsPopup->show(focusedNode->getRect(),
focusedNode->ownerDocument()->view(), 0);
m_suggestionsPopupShowing = true;
}
}
void WebViewImpl::hidePopups()
{
hideSelectPopup();
hideSuggestionsPopup();
}
void WebViewImpl::performCustomContextMenuAction(unsigned action)
{
if (!m_page)
return;
ContextMenu* menu = m_page->contextMenuController()->contextMenu();
if (!menu)
return;
ContextMenuItem* item = menu->itemWithAction(static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + action));
if (item)
m_page->contextMenuController()->contextMenuItemSelected(item);
m_page->contextMenuController()->clearContextMenu();
}
bool WebViewImpl::setDropEffect(bool accept)
{
if (m_dragTargetDispatch) {
m_dropEffect = accept ? DropEffectCopy : DropEffectNone;
return true;
}
return false;
}
void WebViewImpl::setIsTransparent(bool isTransparent)
{
Frame* frame = m_page->mainFrame();
while (frame) {
frame->view()->setTransparent(isTransparent);
frame = frame->tree()->traverseNext();
}
m_isTransparent = isTransparent;
}
bool WebViewImpl::isTransparent() const
{
return m_isTransparent;
}
void WebViewImpl::setIsActive(bool active)
{
if (page() && page()->focusController())
page()->focusController()->setActive(active);
}
bool WebViewImpl::isActive() const
{
return (page() && page()->focusController()) ? page()->focusController()->isActive() : false;
}
void WebViewImpl::setScrollbarColors(unsigned inactiveColor,
unsigned activeColor,
unsigned trackColor) {
#if OS(LINUX)
RenderThemeChromiumLinux::setScrollbarColors(inactiveColor,
activeColor,
trackColor);
#endif
}
void WebViewImpl::setSelectionColors(unsigned activeBackgroundColor,
unsigned activeForegroundColor,
unsigned inactiveBackgroundColor,
unsigned inactiveForegroundColor) {
#if OS(LINUX)
RenderThemeChromiumLinux::setSelectionColors(activeBackgroundColor,
activeForegroundColor,
inactiveBackgroundColor,
inactiveForegroundColor);
theme()->platformColorsDidChange();
#endif
}
void WebViewImpl::addUserScript(const WebString& sourceCode, bool runAtStart)
{
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::create());
pageGroup->addUserScriptToWorld(world.get(), sourceCode, WebURL(), 0, 0,
runAtStart ? InjectAtDocumentStart : InjectAtDocumentEnd);
}
void WebViewImpl::addUserStyleSheet(const WebString& sourceCode)
{
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::create());
pageGroup->addUserStyleSheetToWorld(world.get(), sourceCode, WebURL(), 0, 0);
}
void WebViewImpl::removeAllUserContent()
{
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
pageGroup->removeAllUserContent();
}
void WebViewImpl::didCommitLoad(bool* isNewNavigation)
{
if (isNewNavigation)
*isNewNavigation = m_observedNewNavigation;
#ifndef NDEBUG
ASSERT(!m_observedNewNavigation
|| m_page->mainFrame()->loader()->documentLoader() == m_newNavigationLoader);
m_newNavigationLoader = 0;
#endif
m_observedNewNavigation = false;
}
bool WebViewImpl::navigationPolicyFromMouseEvent(unsigned short button,
bool ctrl, bool shift,
bool alt, bool meta,
WebNavigationPolicy* policy)
{
#if OS(WINDOWS) || OS(LINUX) || OS(FREEBSD) || OS(SOLARIS)
const bool newTabModifier = (button == 1) || ctrl;
#elif OS(DARWIN)
const bool newTabModifier = (button == 1) || meta;
#endif
if (!newTabModifier && !shift && !alt)
return false;
ASSERT(policy);
if (newTabModifier) {
if (shift)
*policy = WebNavigationPolicyNewForegroundTab;
else
*policy = WebNavigationPolicyNewBackgroundTab;
} else {
if (shift)
*policy = WebNavigationPolicyNewWindow;
else
*policy = WebNavigationPolicyDownload;
}
return true;
}
void WebViewImpl::startDragging(const WebDragData& dragData,
WebDragOperationsMask mask,
const WebImage& dragImage,
const WebPoint& dragImageOffset)
{
if (!m_client)
return;
ASSERT(!m_doingDragAndDrop);
m_doingDragAndDrop = true;
m_client->startDragging(dragData, mask, dragImage, dragImageOffset);
}
void WebViewImpl::setCurrentHistoryItem(HistoryItem* item)
{
m_backForwardListClientImpl.setCurrentHistoryItem(item);
}
HistoryItem* WebViewImpl::previousHistoryItem()
{
return m_backForwardListClientImpl.previousHistoryItem();
}
void WebViewImpl::observeNewNavigation()
{
m_observedNewNavigation = true;
#ifndef NDEBUG
m_newNavigationLoader = m_page->mainFrame()->loader()->documentLoader();
#endif
}
void WebViewImpl::setIgnoreInputEvents(bool newValue)
{
ASSERT(m_ignoreInputEvents != newValue);
m_ignoreInputEvents = newValue;
}
#if ENABLE(NOTIFICATIONS)
NotificationPresenterImpl* WebViewImpl::notificationPresenterImpl()
{
if (!m_notificationPresenter.isInitialized() && m_client)
m_notificationPresenter.initialize(m_client->notificationPresenter());
return &m_notificationPresenter;
}
#endif
void WebViewImpl::refreshSuggestionsPopup()
{
ASSERT(m_suggestionsPopupShowing);
if (!m_suggestionsPopupClient->listSize()) {
hideSuggestionsPopup();
return;
}
IntRect oldBounds = m_suggestionsPopup->boundsRect();
m_suggestionsPopup->refresh();
IntRect newBounds = m_suggestionsPopup->boundsRect();
if (oldBounds != newBounds) {
WebPopupMenuImpl* popupMenu =
static_cast<WebPopupMenuImpl*>(m_suggestionsPopup->client());
popupMenu->client()->setWindowRect(newBounds);
}
}
Node* WebViewImpl::focusedWebCoreNode()
{
Frame* frame = m_page->focusController()->focusedFrame();
if (!frame)
return 0;
Document* document = frame->document();
if (!document)
return 0;
return document->focusedNode();
}
HitTestResult WebViewImpl::hitTestResultForWindowPos(const IntPoint& pos)
{
IntPoint docPoint(m_page->mainFrame()->view()->windowToContents(pos));
return m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(docPoint, false);
}
void WebViewImpl::setTabsToLinks(bool enable)
{
m_tabsToLinks = enable;
}
bool WebViewImpl::tabsToLinks() const
{
return m_tabsToLinks;
}
#if USE(ACCELERATED_COMPOSITING)
void WebViewImpl::setRootGraphicsLayer(WebCore::PlatformLayer* layer)
{
setIsAcceleratedCompositingActive(layer ? true : false);
if (m_layerRenderer)
m_layerRenderer->setRootLayer(layer);
}
void WebViewImpl::setIsAcceleratedCompositingActive(bool active)
{
if (m_isAcceleratedCompositingActive == active)
return;
if (active) {
m_layerRenderer = LayerRendererChromium::create();
if (m_layerRenderer)
m_isAcceleratedCompositingActive = true;
} else {
m_layerRenderer = 0;
m_isAcceleratedCompositingActive = false;
}
}
void WebViewImpl::updateRootLayerContents(const WebRect& rect)
{
if (!isAcceleratedCompositingActive())
return;
WebFrameImpl* webframe = mainFrameImpl();
if (!webframe)
return;
FrameView* view = webframe->frameView();
if (!view)
return;
WebRect viewRect = view->frameRect();
SkIRect scrollFrame;
scrollFrame.set(view->scrollX(), view->scrollY(), view->layoutWidth() + view->scrollX(), view->layoutHeight() + view->scrollY());
m_layerRenderer->setScrollFrame(scrollFrame);
LayerChromium* rootLayer = m_layerRenderer->rootLayer();
if (rootLayer) {
IntRect visibleRect = view->visibleContentRect(true);
rootLayer->setBackingStoreRect(IntSize(visibleRect.width(), visibleRect.height()));
GraphicsContext* rootLayerContext = rootLayer->graphicsContext();
rootLayerContext->save();
webframe->paintWithContext(*(rootLayer->graphicsContext()), rect);
rootLayerContext->restore();
}
}
void WebViewImpl::setRootLayerNeedsDisplay()
{
if (WebFrameImpl* webframe = mainFrameImpl()) {
if (FrameView* view = webframe->frameView()) {
IntRect visibleRect = view->visibleContentRect(true);
m_client->didInvalidateRect(visibleRect);
}
}
if (m_layerRenderer)
m_layerRenderer->setNeedsDisplay();
}
#endif
}