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_TOUCH_H_ 6 #define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_VIEW_TOUCH_H_ 7 #pragma once 8 9 #include <vector> 10 11 #include "base/memory/scoped_ptr.h" 12 #include "content/browser/tab_contents/tab_contents_view.h" 13 #include "ui/gfx/size.h" 14 #include "views/view.h" 15 16 class ConstrainedWindowGtk; 17 typedef struct _GtkFloatingContainer GtkFloatingContainer; 18 class RenderViewContextMenuViews; 19 class SadTabView; 20 class SkBitmap; 21 class TabContentsDragSource; 22 class WebDragDestGtk; 23 24 namespace gfx { 25 class Point; 26 } // namespace gfx 27 28 namespace views { 29 class NativeViewHost; 30 } // namespace views 31 32 // Touch-specific implementation of the TabContentsView for the touch UI. 33 class TabContentsViewTouch : public TabContentsView, public views::View { 34 public: 35 // The corresponding TabContents is passed in the constructor, and manages our 36 // lifetime. This doesn't need to be the case, but is this way currently 37 // because that's what was easiest when they were split. 38 explicit TabContentsViewTouch(TabContents* tab_contents); 39 virtual ~TabContentsViewTouch(); 40 41 // Unlike Windows, ConstrainedWindows need to collaborate with the 42 // TabContentsViewTouch to position the dialogs. 43 void AttachConstrainedWindow(ConstrainedWindowGtk* constrained_window); 44 void RemoveConstrainedWindow(ConstrainedWindowGtk* constrained_window); 45 46 // TabContentsView implementation 47 virtual void CreateView(const gfx::Size& initial_size) OVERRIDE; 48 virtual RenderWidgetHostView* CreateViewForWidget( 49 RenderWidgetHost* render_widget_host) OVERRIDE; 50 virtual gfx::NativeView GetNativeView() const OVERRIDE; 51 virtual gfx::NativeView GetContentNativeView() const OVERRIDE; 52 virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; 53 virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE; 54 virtual void SetPageTitle(const std::wstring& title) OVERRIDE; 55 virtual void OnTabCrashed(base::TerminationStatus status, 56 int error_code) OVERRIDE; 57 virtual void SizeContents(const gfx::Size& size) OVERRIDE; 58 virtual void Focus() OVERRIDE; 59 virtual void SetInitialFocus() OVERRIDE; 60 virtual void StoreFocus() OVERRIDE; 61 virtual void RestoreFocus() OVERRIDE; 62 virtual void GetViewBounds(gfx::Rect* out) const OVERRIDE; 63 64 // views::View implementation 65 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; 66 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 67 68 // Backend implementation of RenderViewHostDelegate::View. 69 virtual void ShowContextMenu(const ContextMenuParams& params); 70 virtual void ShowPopupMenu(const gfx::Rect& bounds, 71 int item_height, 72 double item_font_size, 73 int selected_item, 74 const std::vector<WebMenuItem>& items, 75 bool right_aligned) OVERRIDE; 76 virtual void StartDragging(const WebDropData& drop_data, 77 WebKit::WebDragOperationsMask ops_allowed, 78 const SkBitmap& image, 79 const gfx::Point& image_offset) OVERRIDE; 80 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE; 81 virtual void GotFocus() OVERRIDE; 82 virtual void TakeFocus(bool reverse) OVERRIDE; 83 virtual void VisibilityChanged(views::View *, bool is_visible) OVERRIDE; 84 85 private: 86 // Signal handlers ----------------------------------------------------------- 87 88 // Handles notifying the TabContents and other operations when the window was 89 // shown or hidden. 90 void WasHidden(); 91 void WasShown(); 92 93 // Handles resizing of the contents. This will notify the RenderWidgetHostView 94 // of the change, reposition popups, and the find in page bar. 95 void WasSized(const gfx::Size& size); 96 97 // For any floating views (ConstrainedDialogs) this function centers them 98 // within this view. It's called whem a ConstrainedDialog is attached and 99 // when this view is resized. 100 void SetFloatingPosition(const gfx::Size& size); 101 102 // Used to render the sad tab. This will be non-NULL only when the sad tab is 103 // visible. 104 scoped_ptr<SadTabView> sad_tab_; 105 106 // Whether to ignore the next CHAR keyboard event. 107 bool ignore_next_char_event_; 108 109 // The id used in the ViewStorage to store the last focused view. 110 int last_focused_view_storage_id_; 111 112 // The context menu. Callbacks are asynchronous so we need to keep it around. 113 scoped_ptr<RenderViewContextMenuViews> context_menu_; 114 115 // Handle drags from this TabContentsView. 116 // TODO(anicolao): figure out what's needed for drag'n'drop 117 118 // The event for the last mouse down we handled. We need this for drags. 119 GdkEventButton last_mouse_down_; 120 121 // Current size. See comment in WidgetGtk as to why this is cached. 122 gfx::Size size_; 123 124 // Each individual UI for constrained dialogs currently displayed. The 125 // objects in this vector are owned by the TabContents, not the view. 126 std::vector<ConstrainedWindowGtk*> constrained_windows_; 127 128 DISALLOW_COPY_AND_ASSIGN(TabContentsViewTouch); 129 }; 130 131 #endif // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_VIEW_TOUCH_H_ 132