tab_contents_view_mac.h revision 513209b27ff55e2841eac0e4120199c23acce758
1// Copyright (c) 2010 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 CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_MAC_H_
6#define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_MAC_H_
7#pragma once
8
9#import <Cocoa/Cocoa.h>
10
11#include <string>
12#include <vector>
13
14#include "base/scoped_nsobject.h"
15#include "chrome/browser/cocoa/base_view.h"
16#include "chrome/browser/tab_contents/tab_contents_view.h"
17#include "chrome/common/notification_registrar.h"
18#include "gfx/size.h"
19
20@class FocusTracker;
21@class SadTabController;
22class SkBitmap;
23class TabContentsViewMac;
24@class WebDragSource;
25@class WebDropTarget;
26namespace gfx {
27class Point;
28}
29
30@interface TabContentsViewCocoa : BaseView {
31 @private
32  TabContentsViewMac* tabContentsView_;  // WEAK; owns us
33  scoped_nsobject<WebDragSource> dragSource_;
34  scoped_nsobject<WebDropTarget> dropTarget_;
35}
36
37// Expose this, since sometimes one needs both the NSView and the TabContents.
38- (TabContents*)tabContents;
39@end
40
41// Mac-specific implementation of the TabContentsView. It owns an NSView that
42// contains all of the contents of the tab and associated child views.
43class TabContentsViewMac : public TabContentsView,
44                           public NotificationObserver {
45 public:
46  // The corresponding TabContents is passed in the constructor, and manages our
47  // lifetime. This doesn't need to be the case, but is this way currently
48  // because that's what was easiest when they were split.
49  explicit TabContentsViewMac(TabContents* web_contents);
50  virtual ~TabContentsViewMac();
51
52  // TabContentsView implementation --------------------------------------------
53
54  virtual void CreateView(const gfx::Size& initial_size);
55  virtual RenderWidgetHostView* CreateViewForWidget(
56      RenderWidgetHost* render_widget_host);
57  virtual gfx::NativeView GetNativeView() const;
58  virtual gfx::NativeView GetContentNativeView() const;
59  virtual gfx::NativeWindow GetTopLevelNativeWindow() const;
60  virtual void GetContainerBounds(gfx::Rect* out) const;
61  virtual void RenderViewCreated(RenderViewHost* host);
62  virtual void SetPageTitle(const std::wstring& title);
63  virtual void OnTabCrashed();
64  virtual void SizeContents(const gfx::Size& size);
65  virtual void Focus();
66  virtual void SetInitialFocus();
67  virtual void StoreFocus();
68  virtual void RestoreFocus();
69  virtual void UpdatePreferredSize(const gfx::Size& pref_size);
70  virtual RenderWidgetHostView* CreateNewWidgetInternal(
71      int route_id,
72      WebKit::WebPopupType popup_type);
73  virtual void ShowCreatedWidgetInternal(RenderWidgetHostView* widget_host_view,
74                                         const gfx::Rect& initial_pos);
75  virtual bool IsEventTracking() const;
76  virtual void CloseTabAfterEventTracking();
77
78  // Backend implementation of RenderViewHostDelegate::View.
79  virtual void ShowContextMenu(const ContextMenuParams& params);
80  virtual void ShowPopupMenu(const gfx::Rect& bounds,
81                             int item_height,
82                             double item_font_size,
83                             int selected_item,
84                             const std::vector<WebMenuItem>& items,
85                             bool right_aligned);
86  virtual void StartDragging(const WebDropData& drop_data,
87                             WebKit::WebDragOperationsMask allowed_operations,
88                             const SkBitmap& image,
89                             const gfx::Point& image_offset);
90  virtual void UpdateDragCursor(WebKit::WebDragOperation operation);
91  virtual void GotFocus();
92  virtual void TakeFocus(bool reverse);
93
94  // NotificationObserver implementation ---------------------------------------
95
96  virtual void Observe(NotificationType type,
97                       const NotificationSource& source,
98                       const NotificationDetails& details);
99
100  // A helper method for closing the tab in the
101  // CloseTabAfterEventTracking() implementation.
102  void CloseTab();
103
104  int preferred_width() const { return preferred_width_; }
105
106 private:
107  // The Cocoa NSView that lives in the view hierarchy.
108  scoped_nsobject<TabContentsViewCocoa> cocoa_view_;
109
110  // Keeps track of which NSView has focus so we can restore the focus when
111  // focus returns.
112  scoped_nsobject<FocusTracker> focus_tracker_;
113
114  // Used to get notifications about renderers coming and going.
115  NotificationRegistrar registrar_;
116
117  // Used to render the sad tab. This will be non-NULL only when the sad tab is
118  // visible.
119  scoped_nsobject<SadTabController> sad_tab_;
120
121  // The page content's intrinsic width.
122  int preferred_width_;
123
124  DISALLOW_COPY_AND_ASSIGN(TabContentsViewMac);
125};
126
127#endif  // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_MAC_H_
128