Home | History | Annotate | Download | only in web
      1 /*
      2  * Copyright (C) 2009 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef WebPopupMenuImpl_h
     32 #define WebPopupMenuImpl_h
     33 
     34 #include "public/platform/WebContentLayerClient.h"
     35 #include "public/platform/WebPoint.h"
     36 #include "public/platform/WebSize.h"
     37 #include "public/web/WebPopupMenu.h"
     38 #include "web/PopupContainerClient.h"
     39 #include "wtf/OwnPtr.h"
     40 #include "wtf/RefCounted.h"
     41 
     42 namespace blink {
     43 class LocalFrame;
     44 class KeyboardEvent;
     45 class Page;
     46 class PlatformKeyboardEvent;
     47 class Range;
     48 class WebContentLayer;
     49 class WebGestureEvent;
     50 class WebKeyboardEvent;
     51 class WebLayerTreeView;
     52 class WebMouseEvent;
     53 class WebMouseWheelEvent;
     54 class WebRange;
     55 class WebTouchEvent;
     56 class Widget;
     57 struct WebRect;
     58 
     59 class WebPopupMenuImpl : public WebPopupMenu, public PopupContainerClient, public WebContentLayerClient, public RefCounted<WebPopupMenuImpl> {
     60     WTF_MAKE_FAST_ALLOCATED;
     61 public:
     62     // WebWidget functions:
     63     virtual void close() OVERRIDE FINAL;
     64     virtual WebSize size() OVERRIDE FINAL { return m_size; }
     65     virtual void willStartLiveResize() OVERRIDE FINAL;
     66     virtual void resize(const WebSize&) OVERRIDE FINAL;
     67     virtual void willEndLiveResize() OVERRIDE FINAL;
     68     virtual void beginFrame(const WebBeginFrameArgs&) OVERRIDE FINAL;
     69     virtual void layout() OVERRIDE FINAL;
     70     virtual void paint(WebCanvas*, const WebRect&) OVERRIDE FINAL;
     71     virtual void themeChanged() OVERRIDE FINAL;
     72     virtual bool handleInputEvent(const WebInputEvent&) OVERRIDE FINAL;
     73     virtual void mouseCaptureLost() OVERRIDE FINAL;
     74     virtual void setFocus(bool enable) OVERRIDE FINAL;
     75     virtual bool setComposition(
     76         const WebString& text,
     77         const WebVector<WebCompositionUnderline>& underlines,
     78         int selectionStart, int selectionEnd) OVERRIDE FINAL;
     79     virtual bool confirmComposition() OVERRIDE FINAL;
     80     virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) OVERRIDE FINAL;
     81     virtual bool confirmComposition(const WebString& text) OVERRIDE FINAL;
     82     virtual bool compositionRange(size_t* location, size_t* length) OVERRIDE FINAL;
     83     virtual bool caretOrSelectionRange(size_t* location, size_t* length) OVERRIDE FINAL;
     84     virtual void setTextDirection(WebTextDirection) OVERRIDE FINAL;
     85     virtual bool isAcceleratedCompositingActive() const OVERRIDE FINAL { return false; }
     86     virtual bool isPopupMenu() const OVERRIDE FINAL { return true; }
     87     virtual void willCloseLayerTreeView() OVERRIDE FINAL;
     88 
     89     // WebContentLayerClient
     90     virtual void paintContents(WebCanvas*, const WebRect& clip, bool canPaintLCDTest, WebContentLayerClient::GraphicsContextStatus = GraphicsContextEnabled) OVERRIDE FINAL;
     91 
     92     // WebPopupMenuImpl
     93     void initialize(PopupContainer* widget, const WebRect& bounds);
     94 
     95     WebWidgetClient* client() { return m_client; }
     96 
     97     void handleMouseMove(const WebMouseEvent&);
     98     void handleMouseLeave(const WebMouseEvent&);
     99     void handleMouseDown(const WebMouseEvent&);
    100     void handleMouseUp(const WebMouseEvent&);
    101     void handleMouseDoubleClick(const WebMouseEvent&);
    102     void handleMouseWheel(const WebMouseWheelEvent&);
    103     bool handleGestureEvent(const WebGestureEvent&);
    104     bool handleTouchEvent(const WebTouchEvent&);
    105     bool handleKeyEvent(const WebKeyboardEvent&);
    106 
    107    protected:
    108     friend class WebPopupMenu; // For WebPopupMenu::create.
    109     friend class WTF::RefCounted<WebPopupMenuImpl>;
    110 
    111     explicit WebPopupMenuImpl(WebWidgetClient*);
    112     ~WebPopupMenuImpl();
    113 
    114     // HostWindow methods:
    115     virtual void invalidateContentsAndRootView(const IntRect&) OVERRIDE FINAL;
    116     virtual void invalidateContentsForSlowScroll(const IntRect&) OVERRIDE FINAL;
    117     virtual void scheduleAnimation() OVERRIDE FINAL;
    118     virtual IntRect rootViewToScreen(const IntRect&) const OVERRIDE FINAL;
    119     virtual WebScreenInfo screenInfo() const OVERRIDE FINAL;
    120 
    121     // PopupContainerClient methods:
    122     virtual void popupClosed(PopupContainer*) OVERRIDE FINAL;
    123 
    124     WebWidgetClient* m_client;
    125     WebSize m_size;
    126 
    127     WebLayerTreeView* m_layerTreeView;
    128     OwnPtr<WebContentLayer> m_rootLayer;
    129 
    130     WebPoint m_lastMousePosition;
    131 
    132     // This is a non-owning ref. The popup will notify us via popupClosed()
    133     // before it is destroyed.
    134     PopupContainer* m_widget;
    135 };
    136 
    137 DEFINE_TYPE_CASTS(WebPopupMenuImpl, WebWidget, widget, widget->isPopupMenu(), widget.isPopupMenu());
    138 // WebPopupMenuImpl is the only implementation of PopupContainerClient, so
    139 // no need for further checking.
    140 DEFINE_TYPE_CASTS(WebPopupMenuImpl, PopupContainerClient, client, true, true);
    141 
    142 } // namespace blink
    143 
    144 #endif
    145