Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / browser / web_contents / web_contents_view_mac.h
blob93c1eaff906a046b8d3772cb6b2363e281e10020
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.
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
8 #import <Cocoa/Cocoa.h>
10 #include <string>
11 #include <vector>
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"
22 @class FocusTracker;
23 class SkBitmap;
24 @class WebDragDest;
25 @class WebDragSource;
27 namespace content {
28 class PopupMenuHelper;
29 class WebContentsImpl;
30 class WebContentsViewDelegate;
31 class WebContentsViewMac;
34 namespace gfx {
35 class Vector2d;
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_;
47 - (void)setMouseDownCanMoveWindow:(BOOL)canMove;
49 // Expose this, since sometimes one needs both the NSView and the
50 // WebContentsImpl.
51 - (content::WebContentsImpl*)webContents;
52 @end
54 namespace content {
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 ~WebContentsViewMac() override;
68 // WebContentsView implementation --------------------------------------------
69 gfx::NativeView GetNativeView() const override;
70 gfx::NativeView GetContentNativeView() const override;
71 gfx::NativeWindow GetTopLevelNativeWindow() const override;
72 void GetContainerBounds(gfx::Rect* out) const override;
73 void SizeContents(const gfx::Size& size) override;
74 void Focus() override;
75 void SetInitialFocus() override;
76 void StoreFocus() override;
77 void RestoreFocus() override;
78 DropData* GetDropData() const override;
79 gfx::Rect GetViewBounds() const override;
80 void SetAllowOtherViews(bool allow) override;
81 bool GetAllowOtherViews() const override;
82 void CreateView(const gfx::Size& initial_size,
83 gfx::NativeView context) override;
84 RenderWidgetHostViewBase* CreateViewForWidget(
85 RenderWidgetHost* render_widget_host,
86 bool is_guest_view_hack) override;
87 RenderWidgetHostViewBase* CreateViewForPopupWidget(
88 RenderWidgetHost* render_widget_host) override;
89 void SetPageTitle(const base::string16& title) override;
90 void RenderViewCreated(RenderViewHost* host) override;
91 void RenderViewSwappedIn(RenderViewHost* host) override;
92 void SetOverscrollControllerEnabled(bool enabled) override;
93 bool IsEventTracking() const override;
94 void CloseTabAfterEventTracking() override;
96 // Backend implementation of RenderViewHostDelegateView.
97 void ShowContextMenu(RenderFrameHost* render_frame_host,
98 const ContextMenuParams& params) override;
99 void ShowPopupMenu(RenderFrameHost* render_frame_host,
100 const gfx::Rect& bounds,
101 int item_height,
102 double item_font_size,
103 int selected_item,
104 const std::vector<MenuItem>& items,
105 bool right_aligned,
106 bool allow_multiple_selection) override;
107 void HidePopupMenu() override;
108 void StartDragging(const DropData& drop_data,
109 blink::WebDragOperationsMask allowed_operations,
110 const gfx::ImageSkia& image,
111 const gfx::Vector2d& image_offset,
112 const DragEventSourceInfo& event_info) override;
113 void UpdateDragCursor(blink::WebDragOperation operation) override;
114 void GotFocus() override;
115 void TakeFocus(bool reverse) override;
117 // A helper method for closing the tab in the
118 // CloseTabAfterEventTracking() implementation.
119 void CloseTab();
121 WebContentsImpl* web_contents() { return web_contents_; }
122 WebContentsViewDelegate* delegate() { return delegate_.get(); }
124 private:
125 // Returns the fullscreen view, if one exists; otherwise, returns the content
126 // native view. This ensures that the view currently attached to a NSWindow is
127 // being used to query or set first responder state.
128 gfx::NativeView GetNativeViewForFocus() const;
130 // The WebContentsImpl whose contents we display.
131 WebContentsImpl* web_contents_;
133 // The Cocoa NSView that lives in the view hierarchy.
134 base::scoped_nsobject<WebContentsViewCocoa> cocoa_view_;
136 // Keeps track of which NSView has focus so we can restore the focus when
137 // focus returns.
138 base::scoped_nsobject<FocusTracker> focus_tracker_;
140 // Our optional delegate.
141 scoped_ptr<WebContentsViewDelegate> delegate_;
143 // Whether to allow other views.
144 bool allow_other_views_;
146 scoped_ptr<PopupMenuHelper> popup_menu_helper_;
148 DISALLOW_COPY_AND_ASSIGN(WebContentsViewMac);
151 } // namespace content
153 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_