web_contents_view_mac.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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/common/content_export.h" 16#include "content/common/drag_event_source_info.h" 17#include "content/port/browser/render_view_host_delegate_view.h" 18#include "content/port/browser/web_contents_view_port.h" 19#include "ui/base/cocoa/base_view.h" 20#include "ui/gfx/size.h" 21 22@class FocusTracker; 23class SkBitmap; 24@class WebDragDest; 25@class WebDragSource; 26 27namespace content { 28class PopupMenuHelper; 29class WebContentsImpl; 30class WebContentsViewDelegate; 31class WebContentsViewMac; 32} 33 34namespace gfx { 35class Vector2d; 36} 37 38CONTENT_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 54namespace 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. 58class WebContentsViewMac : public WebContentsViewPort, 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 OnTabCrashed(base::TerminationStatus status, 74 int error_code) OVERRIDE; 75 virtual void SizeContents(const gfx::Size& size) OVERRIDE; 76 virtual void Focus() OVERRIDE; 77 virtual void SetInitialFocus() OVERRIDE; 78 virtual void StoreFocus() OVERRIDE; 79 virtual void RestoreFocus() OVERRIDE; 80 virtual DropData* GetDropData() const OVERRIDE; 81 virtual gfx::Rect GetViewBounds() const OVERRIDE; 82 virtual void SetAllowOverlappingViews(bool overlapping) OVERRIDE; 83 virtual bool GetAllowOverlappingViews() const OVERRIDE; 84 virtual void SetOverlayView(WebContentsView* overlay, 85 const gfx::Point& offset) OVERRIDE; 86 virtual void RemoveOverlayView() OVERRIDE; 87 88 // WebContentsViewPort implementation ---------------------------------------- 89 virtual void CreateView( 90 const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE; 91 virtual RenderWidgetHostView* CreateViewForWidget( 92 RenderWidgetHost* render_widget_host) OVERRIDE; 93 virtual RenderWidgetHostView* CreateViewForPopupWidget( 94 RenderWidgetHost* render_widget_host) OVERRIDE; 95 virtual void SetPageTitle(const base::string16& title) OVERRIDE; 96 virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE; 97 virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE; 98 virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE; 99 virtual bool IsEventTracking() const OVERRIDE; 100 virtual void CloseTabAfterEventTracking() OVERRIDE; 101 102 // Backend implementation of RenderViewHostDelegateView. 103 virtual void ShowContextMenu(content::RenderFrameHost* render_frame_host, 104 const ContextMenuParams& params) OVERRIDE; 105 virtual void ShowPopupMenu(const gfx::Rect& bounds, 106 int item_height, 107 double item_font_size, 108 int selected_item, 109 const std::vector<MenuItem>& items, 110 bool right_aligned, 111 bool allow_multiple_selection) OVERRIDE; 112 virtual void HidePopupMenu() OVERRIDE; 113 virtual void StartDragging(const DropData& drop_data, 114 blink::WebDragOperationsMask allowed_operations, 115 const gfx::ImageSkia& image, 116 const gfx::Vector2d& image_offset, 117 const DragEventSourceInfo& event_info) OVERRIDE; 118 virtual void UpdateDragCursor(blink::WebDragOperation operation) OVERRIDE; 119 virtual void GotFocus() OVERRIDE; 120 virtual void TakeFocus(bool reverse) OVERRIDE; 121 122 // A helper method for closing the tab in the 123 // CloseTabAfterEventTracking() implementation. 124 void CloseTab(); 125 126 WebContentsImpl* web_contents() { return web_contents_; } 127 WebContentsViewDelegate* delegate() { return delegate_.get(); } 128 129 private: 130 // Updates overlay view on current RenderWidgetHostView. 131 void UpdateRenderWidgetHostViewOverlay(); 132 133 // The WebContentsImpl whose contents we display. 134 WebContentsImpl* web_contents_; 135 136 // The Cocoa NSView that lives in the view hierarchy. 137 base::scoped_nsobject<WebContentsViewCocoa> cocoa_view_; 138 139 // Keeps track of which NSView has focus so we can restore the focus when 140 // focus returns. 141 base::scoped_nsobject<FocusTracker> focus_tracker_; 142 143 // Our optional delegate. 144 scoped_ptr<WebContentsViewDelegate> delegate_; 145 146 // Whether to allow overlapping views. 147 bool allow_overlapping_views_; 148 149 // The overlay view which is rendered above this one. 150 // Overlay view has |underlay_view_| set to this view. 151 WebContentsViewMac* overlay_view_; 152 153 // The offset of overlay view relative to this view. 154 gfx::Point overlay_view_offset_; 155 156 // The underlay view which this view is rendered above. 157 // Underlay view has |overlay_view_| set to this view. 158 WebContentsViewMac* underlay_view_; 159 160 scoped_ptr<PopupMenuHelper> popup_menu_helper_; 161 162 DISALLOW_COPY_AND_ASSIGN(WebContentsViewMac); 163}; 164 165} // namespace content 166 167#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_ 168