diff options
author | Steve Block <steveblock@google.com> | 2011-05-06 11:45:16 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-05-12 13:44:10 +0100 |
commit | cad810f21b803229eb11403f9209855525a25d57 (patch) | |
tree | 29a6fd0279be608e0fe9ffe9841f722f0f4e4269 /Source/WebCore/page/chromium | |
parent | 121b0cf4517156d0ac5111caf9830c51b69bae8f (diff) | |
download | external_webkit-cad810f21b803229eb11403f9209855525a25d57.zip external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.gz external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.bz2 |
Merge WebKit at r75315: Initial merge by git.
Change-Id: I570314b346ce101c935ed22a626b48c2af266b84
Diffstat (limited to 'Source/WebCore/page/chromium')
-rw-r--r-- | Source/WebCore/page/chromium/ChromeClientChromium.h | 58 | ||||
-rw-r--r-- | Source/WebCore/page/chromium/DragControllerChromium.cpp | 82 | ||||
-rw-r--r-- | Source/WebCore/page/chromium/EventHandlerChromium.cpp | 167 | ||||
-rw-r--r-- | Source/WebCore/page/chromium/FrameChromium.cpp | 118 |
4 files changed, 425 insertions, 0 deletions
diff --git a/Source/WebCore/page/chromium/ChromeClientChromium.h b/Source/WebCore/page/chromium/ChromeClientChromium.h new file mode 100644 index 0000000..02e2a94 --- /dev/null +++ b/Source/WebCore/page/chromium/ChromeClientChromium.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2008, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ChromeClientChromium_h +#define ChromeClientChromium_h + +#include "ChromeClient.h" +#include <wtf/Forward.h> + +namespace WebCore { +class IntRect; +class PopupContainer; + +// Contains Chromium-specific extensions to the ChromeClient. Only put +// things here that don't make sense for other ports. +class ChromeClientChromium : public ChromeClient { +public: + // Notifies the client of a new popup widget. The client should place + // and size the widget with the given bounds, relative to the screen. + // If handleExternal is true, then drawing and input handling for the + // popup will be handled by the external embedder. + virtual void popupOpened(PopupContainer* popupContainer, const IntRect& bounds, + bool handleExternal) = 0; + + // Notifies the client a popup was closed. + virtual void popupClosed(PopupContainer* popupContainer) = 0; +}; + +} // namespace WebCore + +#endif diff --git a/Source/WebCore/page/chromium/DragControllerChromium.cpp b/Source/WebCore/page/chromium/DragControllerChromium.cpp new file mode 100644 index 0000000..de53d19 --- /dev/null +++ b/Source/WebCore/page/chromium/DragControllerChromium.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2008 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "DragController.h" + +#include "DragData.h" +#include "SelectionController.h" +#include <wtf/RefPtr.h> + +#if OS(WINDOWS) +#include <windows.h> +#endif + +namespace WebCore { + +const int DragController::LinkDragBorderInset = 2; +const int DragController::MaxOriginalImageArea = 1500 * 1500; +const int DragController::DragIconRightInset = 7; +const int DragController::DragIconBottomInset = 3; + +const float DragController::DragImageAlpha = 0.75f; + +DragOperation DragController::dragOperation(DragData* dragData) +{ + // FIXME: To match the MacOS behaviour we should return DragOperationNone + // if we are a modal window, we are the drag source, or the window is an + // attached sheet If this can be determined from within WebCore + // operationForDrag can be pulled into WebCore itself + ASSERT(dragData); + return dragData->containsURL() && !m_didInitiateDrag ? DragOperationCopy : DragOperationNone; +} + +bool DragController::isCopyKeyDown() +{ + // FIXME: This should not be OS specific. Delegate to the embedder instead. +#if OS(WINDOWS) + return ::GetAsyncKeyState(VK_CONTROL); +#else + return false; +#endif +} + +const IntSize& DragController::maxDragImageSize() +{ +#if OS(DARWIN) + // Match Safari's drag image size. + static const IntSize maxDragImageSize(400, 400); +#else + static const IntSize maxDragImageSize(200, 200); +#endif + return maxDragImageSize; +} + +void DragController::cleanupAfterSystemDrag() +{ +} + +} // namespace WebCore diff --git a/Source/WebCore/page/chromium/EventHandlerChromium.cpp b/Source/WebCore/page/chromium/EventHandlerChromium.cpp new file mode 100644 index 0000000..9b40fb3 --- /dev/null +++ b/Source/WebCore/page/chromium/EventHandlerChromium.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "EventHandler.h" + +#include "ChromiumDataObject.h" +#include "ClipboardChromium.h" +#include "Cursor.h" +#include "FloatPoint.h" +#include "FocusController.h" +#include "FrameView.h" +#include "Frame.h" +#include "HitTestRequest.h" +#include "HitTestResult.h" +#include "MouseEventWithHitTestResults.h" +#include "NotImplemented.h" +#include "Page.h" +#include "PlatformKeyboardEvent.h" +#include "PlatformWheelEvent.h" +#include "RenderWidget.h" +#include "SelectionController.h" + +namespace WebCore { + +#if OS(DARWIN) +const double EventHandler::TextDragDelay = 0.15; +#else +const double EventHandler::TextDragDelay = 0.0; +#endif + +bool EventHandler::passMousePressEventToSubframe(MouseEventWithHitTestResults& mev, Frame* subframe) +{ + // If we're clicking into a frame that is selected, the frame will appear + // greyed out even though we're clicking on the selection. This looks + // really strange (having the whole frame be greyed out), so we deselect the + // selection. + IntPoint p = m_frame->view()->windowToContents(mev.event().pos()); + if (m_frame->selection()->contains(p)) { + VisiblePosition visiblePos( + mev.targetNode()->renderer()->positionForPoint(mev.localPoint())); + VisibleSelection newSelection(visiblePos); + if (m_frame->selection()->shouldChangeSelection(newSelection)) + m_frame->selection()->setSelection(newSelection); + } + + subframe->eventHandler()->handleMousePressEvent(mev.event()); + return true; +} + +bool EventHandler::passMouseMoveEventToSubframe(MouseEventWithHitTestResults& mev, Frame* subframe, HitTestResult* hoveredNode) +{ + if (m_mouseDownMayStartDrag && !m_mouseDownWasInSubframe) + return false; + subframe->eventHandler()->handleMouseMoveEvent(mev.event(), hoveredNode); + return true; +} + +bool EventHandler::passMouseReleaseEventToSubframe(MouseEventWithHitTestResults& mev, Frame* subframe) +{ + subframe->eventHandler()->handleMouseReleaseEvent(mev.event()); + return true; +} + +bool EventHandler::passWheelEventToWidget(PlatformWheelEvent& wheelEvent, Widget* widget) +{ + // We can sometimes get a null widget! EventHandlerMac handles a null + // widget by returning false, so we do the same. + if (!widget) + return false; + + // If not a FrameView, then probably a plugin widget. Those will receive + // the event via an EventTargetNode dispatch when this returns false. + if (!widget->isFrameView()) + return false; + + return static_cast<FrameView*>(widget)->frame()->eventHandler()->handleWheelEvent(wheelEvent); +} + +bool EventHandler::passWidgetMouseDownEventToWidget(const MouseEventWithHitTestResults& event) +{ + // Figure out which view to send the event to. + if (!event.targetNode() || !event.targetNode()->renderer() || !event.targetNode()->renderer()->isWidget()) + return false; + return passMouseDownEventToWidget(toRenderWidget(event.targetNode()->renderer())->widget()); +} + +bool EventHandler::passMouseDownEventToWidget(Widget* widget) +{ + notImplemented(); + return false; +} + +bool EventHandler::tabsToAllControls(KeyboardEvent*) const +{ + return true; +} + +bool EventHandler::eventActivatedView(const PlatformMouseEvent& event) const +{ + // FIXME: EventHandlerWin.cpp does the following: + // return event.activatedWebView(); + return false; +} + +PassRefPtr<Clipboard> EventHandler::createDraggingClipboard() const +{ + RefPtr<ChromiumDataObjectLegacy> dataObject = ChromiumDataObjectLegacy::create(Clipboard::DragAndDrop); + return ClipboardChromium::create(Clipboard::DragAndDrop, ChromiumDataObject::create(dataObject), ClipboardWritable, m_frame); +} + +void EventHandler::focusDocumentView() +{ + Page* page = m_frame->page(); + if (!page) + return; + page->focusController()->setFocusedFrame(m_frame); +} + +bool EventHandler::passWidgetMouseDownEventToWidget(RenderWidget* renderWidget) +{ + return passMouseDownEventToWidget(renderWidget->widget()); +} + +unsigned EventHandler::accessKeyModifiers() +{ +#if OS(DARWIN) + return PlatformKeyboardEvent::CtrlKey | PlatformKeyboardEvent::AltKey; +#else + return PlatformKeyboardEvent::AltKey; +#endif +} + +#if OS(LINUX) || OS(FREEBSD) +// GTK+ must scroll horizontally if the mouse pointer is on top of the +// horizontal scrollbar while scrolling with the wheel. +// This code comes from gtk/EventHandlerGtk.cpp. +bool EventHandler::shouldTurnVerticalTicksIntoHorizontal(const HitTestResult& result) const +{ + return result.scrollbar() && result.scrollbar()->orientation() == HorizontalScrollbar; +} +#endif + +} // namespace WebCore diff --git a/Source/WebCore/page/chromium/FrameChromium.cpp b/Source/WebCore/page/chromium/FrameChromium.cpp new file mode 100644 index 0000000..15ff8b4 --- /dev/null +++ b/Source/WebCore/page/chromium/FrameChromium.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "Document.h" +#include "FloatRect.h" +#include "ImageBuffer.h" +#include "RenderView.h" +#include "Settings.h" + +namespace WebCore { + +namespace { + +struct ScopedState { + ScopedState(Frame* theFrame, RenderObject* theRenderer) + : frame(theFrame) + , renderer(theRenderer) + , paintBehavior(frame->view()->paintBehavior()) + , backgroundColor(frame->view()->baseBackgroundColor()) + { + } + + ~ScopedState() + { + if (renderer) + renderer->updateDragState(false); + frame->view()->setPaintBehavior(paintBehavior); + frame->view()->setBaseBackgroundColor(backgroundColor); + frame->view()->setNodeToDraw(0); + } + + Frame* frame; + RenderObject* renderer; + PaintBehavior paintBehavior; + Color backgroundColor; +}; + +} // namespace + +DragImageRef Frame::nodeImage(Node* node) +{ + RenderObject* renderer = node->renderer(); + if (!renderer) + return 0; + + const ScopedState state(this, renderer); + + renderer->updateDragState(true); + m_view->setPaintBehavior(state.paintBehavior | PaintBehaviorFlattenCompositingLayers); + // When generating the drag image for an element, ignore the document background. + m_view->setBaseBackgroundColor(colorWithOverrideAlpha(Color::white, 1.0)); + m_doc->updateLayout(); + m_view->setNodeToDraw(node); // Enable special sub-tree drawing mode. + + IntRect topLevelRect; + IntRect paintingRect = renderer->paintingRootRect(topLevelRect); + + OwnPtr<ImageBuffer> buffer(ImageBuffer::create(paintingRect.size())); + if (!buffer) + return 0; + buffer->context()->translate(-paintingRect.x(), -paintingRect.y()); + buffer->context()->clip(FloatRect(0, 0, paintingRect.right(), paintingRect.bottom())); + + m_view->paintContents(buffer->context(), paintingRect); + + RefPtr<Image> image = buffer->copyImage(); + return createDragImageFromImage(image.get()); +} + +DragImageRef Frame::dragImageForSelection() +{ + if (!selection()->isRange()) + return 0; + + const ScopedState state(this, 0); + m_view->setPaintBehavior(PaintBehaviorSelectionOnly); + m_doc->updateLayout(); + + IntRect paintingRect = enclosingIntRect(selection()->bounds()); + + OwnPtr<ImageBuffer> buffer(ImageBuffer::create(paintingRect.size())); + if (!buffer) + return 0; + buffer->context()->translate(-paintingRect.x(), -paintingRect.y()); + buffer->context()->clip(FloatRect(0, 0, paintingRect.right(), paintingRect.bottom())); + + m_view->paintContents(buffer->context(), paintingRect); + + RefPtr<Image> image = buffer->copyImage(); + return createDragImageFromImage(image.get()); +} + +} // namespace WebCore |