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_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_VIEW_VIEWS_H_
      6 #define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_VIEW_VIEWS_H_
      7 #pragma once
      8 
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/timer.h"
     11 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h"
     12 #include "content/browser/tab_contents/tab_contents_view.h"
     13 
     14 class NativeTabContentsView;
     15 class RenderViewContextMenuViews;
     16 class SadTabView;
     17 class SkBitmap;
     18 struct WebDropData;
     19 namespace gfx {
     20 class Point;
     21 class Size;
     22 }
     23 namespace views {
     24 class Widget;
     25 }
     26 
     27 // Views-specific implementation of the TabContentsView.
     28 // TODO(beng): Remove last remnants of Windows-specificity, and make this
     29 //             subclass Widget.
     30 class TabContentsViewViews : public TabContentsView,
     31                              public internal::NativeTabContentsViewDelegate {
     32  public:
     33   // The corresponding TabContents is passed in the constructor, and manages our
     34   // lifetime. This doesn't need to be the case, but is this way currently
     35   // because that's what was easiest when they were split.
     36   explicit TabContentsViewViews(TabContents* tab_contents);
     37   virtual ~TabContentsViewViews();
     38 
     39   // Reset the native parent of this view to NULL.  Unparented windows should
     40   // not receive any messages.
     41   virtual void Unparent();
     42 
     43   // Overridden from TabContentsView:
     44   virtual void CreateView(const gfx::Size& initial_size) OVERRIDE;
     45   virtual RenderWidgetHostView* CreateViewForWidget(
     46       RenderWidgetHost* render_widget_host) OVERRIDE;
     47   virtual gfx::NativeView GetNativeView() const OVERRIDE;
     48   virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
     49   virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE;
     50   virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
     51   virtual void SetPageTitle(const std::wstring& title) OVERRIDE;
     52   virtual void OnTabCrashed(base::TerminationStatus status,
     53                             int error_code) OVERRIDE;
     54   virtual void SizeContents(const gfx::Size& size) OVERRIDE;
     55   virtual void Focus() OVERRIDE;
     56   virtual void SetInitialFocus() OVERRIDE;
     57   virtual void StoreFocus() OVERRIDE;
     58   virtual void RestoreFocus() OVERRIDE;
     59   virtual bool IsDoingDrag() const OVERRIDE;
     60   virtual void CancelDragAndCloseTab() OVERRIDE;
     61   virtual void GetViewBounds(gfx::Rect* out) const OVERRIDE;
     62   virtual void ShowContextMenu(const ContextMenuParams& params) OVERRIDE;
     63   virtual void ShowPopupMenu(const gfx::Rect& bounds,
     64                              int item_height,
     65                              double item_font_size,
     66                              int selected_item,
     67                              const std::vector<WebMenuItem>& items,
     68                              bool right_aligned) OVERRIDE;
     69   virtual void StartDragging(const WebDropData& drop_data,
     70                              WebKit::WebDragOperationsMask operations,
     71                              const SkBitmap& image,
     72                              const gfx::Point& image_offset) OVERRIDE;
     73   virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE;
     74   virtual void GotFocus() OVERRIDE;
     75   virtual void TakeFocus(bool reverse) OVERRIDE;
     76 
     77  private:
     78   // Overridden from internal::NativeTabContentsViewDelegate:
     79   virtual TabContents* GetTabContents() OVERRIDE;
     80   virtual bool IsShowingSadTab() const OVERRIDE;
     81   virtual void OnNativeTabContentsViewShown() OVERRIDE;
     82   virtual void OnNativeTabContentsViewHidden() OVERRIDE;
     83   virtual void OnNativeTabContentsViewSized(const gfx::Size& size) OVERRIDE;
     84   virtual void OnNativeTabContentsViewWheelZoom(int distance) OVERRIDE;
     85   virtual void OnNativeTabContentsViewMouseDown() OVERRIDE;
     86   virtual void OnNativeTabContentsViewMouseMove() OVERRIDE;
     87   virtual void OnNativeTabContentsViewDraggingEnded() OVERRIDE;
     88 
     89   views::Widget* GetWidget();
     90   const views::Widget* GetWidget() const;
     91 
     92   // A helper method for closing the tab.
     93   void CloseTab();
     94 
     95   // Windows events ------------------------------------------------------------
     96 
     97   // Handles notifying the TabContents and other operations when the window was
     98   // shown or hidden.
     99   void WasHidden();
    100   void WasShown();
    101 
    102   // Handles resizing of the contents. This will notify the RenderWidgetHostView
    103   // of the change, reposition popups, and the find in page bar.
    104   void WasSized(const gfx::Size& size);
    105 
    106   // TODO(brettw) comment these. They're confusing.
    107   void WheelZoom(int distance);
    108 
    109   // ---------------------------------------------------------------------------
    110 
    111   scoped_ptr<NativeTabContentsView> native_tab_contents_view_;
    112 
    113   // Used to render the sad tab. This will be non-NULL only when the sad tab is
    114   // visible.
    115   SadTabView* sad_tab_;
    116 
    117   // The id used in the ViewStorage to store the last focused view.
    118   int last_focused_view_storage_id_;
    119 
    120   // The context menu. Callbacks are asynchronous so we need to keep it around.
    121   scoped_ptr<RenderViewContextMenuViews> context_menu_;
    122 
    123   // Set to true if we want to close the tab after the system drag operation
    124   // has finished.
    125   bool close_tab_after_drag_ends_;
    126 
    127   // Used to close the tab after the stack has unwound.
    128   base::OneShotTimer<TabContentsViewViews> close_tab_timer_;
    129 
    130   DISALLOW_COPY_AND_ASSIGN(TabContentsViewViews);
    131 };
    132 
    133 #endif  // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_VIEW_VIEWS_H_
    134