Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / browser / web_contents / web_contents_view_mac.h
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_MAC_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
7
8 #import <Cocoa/Cocoa.h>
9
10 #include <string>
11 #include <vector>
12
13 #include "base/mac/scoped_nsobject.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
16 #include "content/browser/web_contents/web_contents_view.h"
17 #include "content/common/content_export.h"
18 #include "content/common/drag_event_source_info.h"
19 #include "ui/base/cocoa/base_view.h"
20 #include "ui/gfx/size.h"
21
22 @class FocusTracker;
23 class SkBitmap;
24 @class WebDragDest;
25 @class WebDragSource;
26
27 namespace content {
28 class PopupMenuHelper;
29 class WebContentsImpl;
30 class WebContentsViewDelegate;
31 class WebContentsViewMac;
32 }
33
34 namespace gfx {
35 class Vector2d;
36 }
37
38 CONTENT_EXPORT
39 @interface WebContentsViewCocoa : BaseView {
40  @private
41   content::WebContentsViewMac* webContentsView_;  // WEAK; owns us
42   base::scoped_nsobject<WebDragSource> dragSource_;
43   base::scoped_nsobject<WebDragDest> dragDest_;
44   BOOL mouseDownCanMoveWindow_;
45 }
46
47 - (void)setMouseDownCanMoveWindow:(BOOL)canMove;
48
49 // Expose this, since sometimes one needs both the NSView and the
50 // WebContentsImpl.
51 - (content::WebContentsImpl*)webContents;
52 @end
53
54 namespace content {
55
56 // Mac-specific implementation of the WebContentsView. It owns an NSView that
57 // contains all of the contents of the tab and associated child views.
58 class WebContentsViewMac : public WebContentsView,
59                            public RenderViewHostDelegateView {
60  public:
61   // The corresponding WebContentsImpl is passed in the constructor, and manages
62   // our lifetime. This doesn't need to be the case, but is this way currently
63   // because that's what was easiest when they were split.
64   WebContentsViewMac(WebContentsImpl* web_contents,
65                      WebContentsViewDelegate* delegate);
66   virtual ~WebContentsViewMac();
67
68   // WebContentsView implementation --------------------------------------------
69   virtual gfx::NativeView GetNativeView() const OVERRIDE;
70   virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
71   virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE;
72   virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
73   virtual void SizeContents(const gfx::Size& size) OVERRIDE;
74   virtual void Focus() OVERRIDE;
75   virtual void SetInitialFocus() OVERRIDE;
76   virtual void StoreFocus() OVERRIDE;
77   virtual void RestoreFocus() OVERRIDE;
78   virtual DropData* GetDropData() const OVERRIDE;
79   virtual gfx::Rect GetViewBounds() const OVERRIDE;
80   virtual void SetAllowOtherViews(bool allow) OVERRIDE;
81   virtual bool GetAllowOtherViews() const OVERRIDE;
82   virtual void CreateView(
83       const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE;
84   virtual RenderWidgetHostViewBase* CreateViewForWidget(
85       RenderWidgetHost* render_widget_host) OVERRIDE;
86   virtual RenderWidgetHostViewBase* CreateViewForPopupWidget(
87       RenderWidgetHost* render_widget_host) OVERRIDE;
88   virtual void SetPageTitle(const base::string16& title) OVERRIDE;
89   virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE;
90   virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE;
91   virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE;
92   virtual bool IsEventTracking() const OVERRIDE;
93   virtual void CloseTabAfterEventTracking() OVERRIDE;
94
95   // Backend implementation of RenderViewHostDelegateView.
96   virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
97                                const ContextMenuParams& params) OVERRIDE;
98   virtual void ShowPopupMenu(RenderFrameHost* render_frame_host,
99                              const gfx::Rect& bounds,
100                              int item_height,
101                              double item_font_size,
102                              int selected_item,
103                              const std::vector<MenuItem>& items,
104                              bool right_aligned,
105                              bool allow_multiple_selection) OVERRIDE;
106   virtual void HidePopupMenu() OVERRIDE;
107   virtual void StartDragging(const DropData& drop_data,
108                              blink::WebDragOperationsMask allowed_operations,
109                              const gfx::ImageSkia& image,
110                              const gfx::Vector2d& image_offset,
111                              const DragEventSourceInfo& event_info) OVERRIDE;
112   virtual void UpdateDragCursor(blink::WebDragOperation operation) OVERRIDE;
113   virtual void GotFocus() OVERRIDE;
114   virtual void TakeFocus(bool reverse) OVERRIDE;
115
116   // A helper method for closing the tab in the
117   // CloseTabAfterEventTracking() implementation.
118   void CloseTab();
119
120   WebContentsImpl* web_contents() { return web_contents_; }
121   WebContentsViewDelegate* delegate() { return delegate_.get(); }
122
123  private:
124   // The WebContentsImpl whose contents we display.
125   WebContentsImpl* web_contents_;
126
127   // The Cocoa NSView that lives in the view hierarchy.
128   base::scoped_nsobject<WebContentsViewCocoa> cocoa_view_;
129
130   // Keeps track of which NSView has focus so we can restore the focus when
131   // focus returns.
132   base::scoped_nsobject<FocusTracker> focus_tracker_;
133
134   // Our optional delegate.
135   scoped_ptr<WebContentsViewDelegate> delegate_;
136
137   // Whether to allow other views.
138   bool allow_other_views_;
139
140   scoped_ptr<PopupMenuHelper> popup_menu_helper_;
141
142   DISALLOW_COPY_AND_ASSIGN(WebContentsViewMac);
143 };
144
145 }  // namespace content
146
147 #endif  // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_