Home | History | Annotate | Download | only in web_contents
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_WIN_H_
      6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_WIN_H_
      7 
      8 #include "base/memory/ref_counted.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/timer/timer.h"
     11 #include "base/win/win_util.h"
     12 #include "content/common/content_export.h"
     13 #include "content/common/drag_event_source_info.h"
     14 #include "content/port/browser/render_view_host_delegate_view.h"
     15 #include "content/port/browser/web_contents_view_port.h"
     16 #include "ui/base/win/window_impl.h"
     17 
     18 namespace ui {
     19 class HWNDMessageFilter;
     20 }
     21 
     22 namespace content {
     23 class WebContentsDragWin;
     24 class WebContentsImpl;
     25 class WebContentsViewDelegate;
     26 class WebDragDest;
     27 
     28 // An implementation of WebContentsView for Windows.
     29 class CONTENT_EXPORT WebContentsViewWin
     30     : public WebContentsViewPort,
     31       public RenderViewHostDelegateView,
     32       public ui::WindowImpl {
     33  public:
     34   WebContentsViewWin(WebContentsImpl* web_contents,
     35                      WebContentsViewDelegate* delegate);
     36   virtual ~WebContentsViewWin();
     37 
     38   BEGIN_MSG_MAP_EX(WebContentsViewWin)
     39     MESSAGE_HANDLER(WM_CREATE, OnCreate)
     40     MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
     41     MESSAGE_HANDLER(WM_WINDOWPOSCHANGED, OnWindowPosChanged)
     42     MESSAGE_HANDLER(WM_LBUTTONDOWN, OnMouseDown)
     43     MESSAGE_HANDLER(WM_MBUTTONDOWN, OnMouseDown)
     44     MESSAGE_HANDLER(WM_RBUTTONDOWN, OnMouseDown)
     45     MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
     46     // Hacks for old ThinkPad touchpads/scroll points.
     47     MESSAGE_HANDLER(WM_NCCALCSIZE, OnNCCalcSize)
     48     MESSAGE_HANDLER(WM_NCHITTEST, OnNCHitTest)
     49     MESSAGE_HANDLER(WM_HSCROLL, OnScroll)
     50     MESSAGE_HANDLER(WM_VSCROLL, OnScroll)
     51     MESSAGE_HANDLER(WM_SIZE, OnSize)
     52   END_MSG_MAP()
     53 
     54   // Overridden from WebContentsView:
     55   virtual gfx::NativeView GetNativeView() const OVERRIDE;
     56   virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
     57   virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE;
     58   virtual void GetContainerBounds(gfx::Rect *out) const OVERRIDE;
     59   virtual void OnTabCrashed(base::TerminationStatus status,
     60                             int error_code) OVERRIDE;
     61   virtual void SizeContents(const gfx::Size& size) OVERRIDE;
     62   virtual void Focus() OVERRIDE;
     63   virtual void SetInitialFocus() OVERRIDE;
     64   virtual void StoreFocus() OVERRIDE;
     65   virtual void RestoreFocus() OVERRIDE;
     66   virtual DropData* GetDropData() const OVERRIDE;
     67   virtual gfx::Rect GetViewBounds() const OVERRIDE;
     68 
     69   // Overridden from WebContentsViewPort:
     70   virtual void CreateView(
     71       const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE;
     72   virtual RenderWidgetHostView* CreateViewForWidget(
     73       RenderWidgetHost* render_widget_host) OVERRIDE;
     74   virtual RenderWidgetHostView* CreateViewForPopupWidget(
     75       RenderWidgetHost* render_widget_host) OVERRIDE;
     76   virtual void SetPageTitle(const string16& title) OVERRIDE;
     77   virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE;
     78   virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE;
     79   virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE;
     80 
     81   // Implementation of RenderViewHostDelegateView.
     82   virtual void ShowContextMenu(const ContextMenuParams& params) OVERRIDE;
     83   virtual void ShowPopupMenu(const gfx::Rect& bounds,
     84                              int item_height,
     85                              double item_font_size,
     86                              int selected_item,
     87                              const std::vector<MenuItem>& items,
     88                              bool right_aligned,
     89                              bool allow_multiple_selection) OVERRIDE;
     90   virtual void StartDragging(const DropData& drop_data,
     91                              WebKit::WebDragOperationsMask operations,
     92                              const gfx::ImageSkia& image,
     93                              const gfx::Vector2d& image_offset,
     94                              const DragEventSourceInfo& event_info) OVERRIDE;
     95   virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE;
     96   virtual void GotFocus() OVERRIDE;
     97   virtual void TakeFocus(bool reverse) OVERRIDE;
     98 
     99   WebContentsImpl* web_contents() const { return web_contents_; }
    100 
    101  private:
    102   void EndDragging();
    103   void CloseTab();
    104 
    105   LRESULT OnCreate(
    106       UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
    107   LRESULT OnDestroy(
    108       UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
    109   LRESULT OnWindowPosChanged(
    110       UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
    111   LRESULT OnMouseDown(
    112       UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
    113   LRESULT OnMouseMove(
    114       UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
    115   LRESULT OnReflectedMessage(
    116       UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
    117   LRESULT OnNCCalcSize(
    118       UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
    119   LRESULT OnNCHitTest(
    120       UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
    121   LRESULT OnScroll(
    122       UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
    123   LRESULT OnSize(
    124       UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
    125 
    126   gfx::Size initial_size_;
    127 
    128   // The WebContentsImpl whose contents we display.
    129   WebContentsImpl* web_contents_;
    130 
    131   scoped_ptr<WebContentsViewDelegate> delegate_;
    132 
    133   // The helper object that handles drag destination related interactions with
    134   // Windows.
    135   scoped_refptr<WebDragDest> drag_dest_;
    136 
    137   // Used to handle the drag-and-drop.
    138   scoped_refptr<WebContentsDragWin> drag_handler_;
    139 
    140   scoped_ptr<ui::HWNDMessageFilter> hwnd_message_filter_;
    141 
    142   DISALLOW_COPY_AND_ASSIGN(WebContentsViewWin);
    143 };
    144 
    145 } // namespace content
    146 
    147 #endif  // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_WIN_H_
    148