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