| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_APP_LAUNCHER_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_APP_LAUNCHER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_APP_LAUNCHER_H_ | 6 #define CHROME_BROWSER_VIEWS_APP_LAUNCHER_H_ |
| 7 | 7 |
| 8 #include <gtk/gtk.h> | |
| 9 | |
| 10 #include "app/active_window_watcher_x.h" | |
| 11 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 12 #include "base/task.h" | |
| 13 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 9 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 14 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" | 10 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 11 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
| 12 #include "chrome/browser/views/info_bubble.h" |
| 16 #include "chrome/common/renderer_preferences.h" | 13 #include "chrome/common/renderer_preferences.h" |
| 17 #include "views/view.h" | 14 #include "views/view.h" |
| 18 | 15 |
| 19 class Browser; | 16 class Browser; |
| 20 class RenderWidgetHostViewGtk; | |
| 21 class SiteInstance; | 17 class SiteInstance; |
| 22 | 18 |
| 23 namespace gfx { | 19 namespace gfx { |
| 24 class Size; | 20 class Size; |
| 25 } | 21 } |
| 26 namespace views { | 22 namespace views { |
| 27 class NativeViewHost; | 23 class NativeViewHost; |
| 28 class View; | 24 class View; |
| 29 class WidgetGtk; | 25 class WidgetGtk; |
| 30 } | 26 } |
| 31 | 27 |
| 32 namespace chromeos { | 28 class InfoBubbleContentsView; |
| 33 | |
| 34 class NavigationBar; | 29 class NavigationBar; |
| 30 class TabContentsDelegateImpl; |
| 35 | 31 |
| 36 // AppLauncher manages showing the application launcher and optionally the | 32 // AppLauncher manages showing the application launcher and optionally the |
| 37 // navigation bar in compact navigation bar mode. The app launcher is | 33 // navigation bar in compact navigation bar mode. The app launcher is |
| 38 // currently an HTML page. When the user clicks a link on the page a | 34 // currently an HTML page. When the user clicks a link on the page a |
| 39 // new tab is added to the current browser and the app launcher is hidden. | 35 // new tab is added to the current browser and the app launcher is hidden. |
| 40 // When the user opens a new page from the navigation bar, it opens a | 36 // When the user opens a new page from the navigation bar, it opens a |
| 41 // new tab on left, on right or clobbers the current tab depending on | 37 // new tab on left, on right or clobbers the current tab depending on |
| 42 // the configuration. | 38 // the configuration. |
| 43 // | 39 // |
| 44 // To show the app launcher invoke Show. | 40 // To show the app launcher invoke Show. |
| 45 // | 41 // |
| 46 // AppLauncher creates a RenderViewHost and corresponding RenderWidgetHostView | 42 // AppLauncher creates a RenderViewHost and corresponding RenderWidgetHostView |
| 47 // to display the html page. AppLauncher acts as the RenderViewHostDelegate for | 43 // to display the html page. AppLauncher acts as the RenderViewHostDelegate for |
| 48 // the RenderViewHost. Clicking on a link results in creating a new | 44 // the RenderViewHost. Clicking on a link results in creating a new |
| 49 // TabContents (assigned to pending_contents_). One of two things can then | 45 // TabContents (assigned to pending_contents_). One of two things can then |
| 50 // happen: | 46 // happen: |
| 51 // . If the page is a popup (ShowCreatedWindow passed NEW_POPUP), the | 47 // . If the page is a popup (ShowCreatedWindow passed NEW_POPUP), the |
| 52 // TabContents is added to the Browser. | 48 // TabContents is added to the Browser. |
| 53 // . If the page requests a URL to be open (OpenURLFromTab), OpenURL is | 49 // . If the page requests a URL to be open (OpenURLFromTab), OpenURL is |
| 54 // invoked on the browser. | 50 // invoked on the browser. |
| 55 // | 51 // |
| 56 // When a new url is opened, or the user clicks outsides the bounds of the | 52 // When a new url is opened, or the user clicks outsides the bounds of the |
| 57 // widget the app launcher is closed. | 53 // widget the app launcher is closed. |
| 58 class AppLauncher : public RenderViewHostDelegate, | 54 class AppLauncher : public InfoBubbleDelegate, |
| 59 public RenderViewHostDelegate::View, | 55 public RenderViewHostDelegate, |
| 60 public ActiveWindowWatcherX::Observer, | 56 public RenderViewHostDelegate::View { |
| 61 public views::AcceleratorTarget { | |
| 62 public: | 57 public: |
| 63 AppLauncher(); | 58 // Shows an application launcher bubble pointing to the new tab button. |
| 64 ~AppLauncher(); | 59 // The caller DOES NOT OWN the AppLauncher returned. It is deleted |
| 60 // automatically when the AppLauncher is closed. |
| 61 static AppLauncher* Show(Browser* browser); |
| 65 | 62 |
| 66 // Shows the menu. | 63 // Returns the browser this AppLauncher is associated with. |
| 67 void Show(Browser* browser); | 64 Browser* browser() const { return browser_; } |
| 68 | |
| 69 private: | |
| 70 // TabContentsDelegate and RenderViewHostDelegate::View have some methods | |
| 71 // in common (with differing signatures). The TabContentsDelegate methods are | |
| 72 // implemented by this class. | |
| 73 class TabContentsDelegateImpl : public TabContentsDelegate { | |
| 74 public: | |
| 75 explicit TabContentsDelegateImpl(AppLauncher* app_launcher); | |
| 76 | |
| 77 // TabContentsDelegate. | |
| 78 virtual void OpenURLFromTab(TabContents* source, | |
| 79 const GURL& url, const GURL& referrer, | |
| 80 WindowOpenDisposition disposition, | |
| 81 PageTransition::Type transition); | |
| 82 virtual void NavigationStateChanged(const TabContents* source, | |
| 83 unsigned changed_flags) {} | |
| 84 virtual void AddNewContents(TabContents* source, | |
| 85 TabContents* new_contents, | |
| 86 WindowOpenDisposition disposition, | |
| 87 const gfx::Rect& initial_pos, | |
| 88 bool user_gesture) {} | |
| 89 virtual void ActivateContents(TabContents* contents) {} | |
| 90 virtual void LoadingStateChanged(TabContents* source) {} | |
| 91 virtual void CloseContents(TabContents* source) {} | |
| 92 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} | |
| 93 virtual bool IsPopup(TabContents* source) { return false; } | |
| 94 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {} | |
| 95 virtual void URLStarredChanged(TabContents* source, bool starred) {} | |
| 96 virtual void UpdateTargetURL(TabContents* source, const GURL& url) {} | |
| 97 | |
| 98 private: | |
| 99 AppLauncher* app_launcher_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(TabContentsDelegateImpl); | |
| 102 }; | |
| 103 | |
| 104 class TopContainer : public views::View { | |
| 105 public: | |
| 106 explicit TopContainer(AppLauncher* app_launcher); | |
| 107 virtual ~TopContainer() {} | |
| 108 | |
| 109 // views::View overrides. | |
| 110 virtual void Layout(); | |
| 111 virtual bool OnMousePressed(const views::MouseEvent& event); | |
| 112 | |
| 113 private: | |
| 114 AppLauncher* app_launcher_; | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(TopContainer); | |
| 117 }; | |
| 118 | |
| 119 class BubbleContainer : public views::View { | |
| 120 public: | |
| 121 explicit BubbleContainer(AppLauncher* app_launcher); | |
| 122 | |
| 123 // views::View overrides. | |
| 124 virtual void Layout(); | |
| 125 | |
| 126 private: | |
| 127 AppLauncher* app_launcher_; | |
| 128 | |
| 129 DISALLOW_COPY_AND_ASSIGN(BubbleContainer); | |
| 130 }; | |
| 131 | |
| 132 friend class BubbleContainer; | |
| 133 friend class NavigationBar; | |
| 134 friend class TabContentsDelegateImpl; | |
| 135 friend class TopContainer; | |
| 136 | 65 |
| 137 // Hides the app launcher. | 66 // Hides the app launcher. |
| 138 void Hide(); | 67 void Hide(); |
| 139 | 68 |
| 140 // Cleans up state. This is invoked before showing and after a delay when | 69 // InfoBubbleDelegate overrides. |
| 141 // hidden. | 70 virtual void InfoBubbleClosing(InfoBubble* info_bubble, |
| 142 void Cleanup(); | 71 bool closed_by_escape); |
| 143 | 72 virtual bool CloseOnEscape() { return true; } |
| 144 // Updates the app launcher's state and layout with the |browser|. | |
| 145 void Update(Browser* browser); | |
| 146 | 73 |
| 147 // RenderViewHostDelegate overrides. | 74 // RenderViewHostDelegate overrides. |
| 148 virtual int GetBrowserWindowID() const { | 75 virtual int GetBrowserWindowID() const { |
| 149 return -1; | 76 return -1; |
| 150 } | 77 } |
| 151 virtual ViewType::Type GetRenderViewType() const { | 78 virtual ViewType::Type GetRenderViewType() const { |
| 152 return ViewType::INVALID; | 79 return ViewType::INVALID; |
| 153 } | 80 } |
| 154 virtual RenderViewHostDelegate::View* GetViewDelegate() { | 81 virtual RenderViewHostDelegate::View* GetViewDelegate() { |
| 155 return this; | 82 return this; |
| 156 } | 83 } |
| 157 virtual void RequestMove(const gfx::Rect& new_bounds); | 84 virtual void RequestMove(const gfx::Rect& new_bounds); |
| 158 virtual RendererPreferences GetRendererPrefs(Profile* profile) const; | 85 virtual RendererPreferences GetRendererPrefs(Profile* profile) const; |
| 159 | 86 |
| 160 // RenderViewHostDelegate::View overrides. | 87 // RenderViewHostDelegate::View overrides. |
| 161 virtual void CreateNewWindow(int route_id); | 88 virtual void CreateNewWindow(int route_id); |
| 162 virtual void CreateNewWidget(int route_id, bool activatable) {} | 89 virtual void CreateNewWidget(int route_id, bool activatable) {} |
| 163 virtual void ShowCreatedWindow(int route_id, | 90 virtual void ShowCreatedWindow(int route_id, |
| 164 WindowOpenDisposition disposition, | 91 WindowOpenDisposition disposition, |
| 165 const gfx::Rect& initial_pos, | 92 const gfx::Rect& initial_pos, |
| 166 bool user_gesture); | 93 bool user_gesture); |
| 167 virtual void ShowCreatedWidget(int route_id, | 94 virtual void ShowCreatedWidget(int route_id, |
| 168 const gfx::Rect& initial_pos) {} | 95 const gfx::Rect& initial_pos) {} |
| 169 virtual void ShowContextMenu(const ContextMenuParams& params) {} | 96 virtual void ShowContextMenu(const ContextMenuParams& params) {} |
| 170 virtual void StartDragging(const WebDropData& drop_data, | 97 virtual void StartDragging(const WebDropData& drop_data, |
| 171 WebKit::WebDragOperationsMask allowed_ops); | 98 WebKit::WebDragOperationsMask allowed_ops, |
| 99 const SkBitmap& image, |
| 100 const gfx::Point& image_offset); |
| 172 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} | 101 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} |
| 173 virtual void GotFocus() {} | 102 virtual void GotFocus() {} |
| 174 virtual void TakeFocus(bool reverse) {} | 103 virtual void TakeFocus(bool reverse) {} |
| 175 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 104 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 176 bool* is_keyboard_shortcut) { | 105 bool* is_keyboard_shortcut) { |
| 177 return false; | 106 return false; |
| 178 } | 107 } |
| 179 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} | 108 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} |
| 180 virtual void HandleMouseEvent() {} | 109 virtual void HandleMouseEvent() {} |
| 181 virtual void HandleMouseLeave() {} | 110 virtual void HandleMouseLeave() {} |
| 182 virtual void UpdatePreferredSize(const gfx::Size& pref_size) {} | 111 virtual void UpdatePreferredSize(const gfx::Size& pref_size) {} |
| 183 | 112 |
| 184 // ActiveWindowWatcherX::Observer implementation. | 113 private: |
| 185 virtual void ActiveWindowChanged(GdkWindow* active_window); | 114 friend class DeleteTask<AppLauncher>; |
| 115 friend class NavigationBar; |
| 116 friend class InfoBubbleContentsView; |
| 186 | 117 |
| 187 // views::AcceleratorTarget implementation: | 118 explicit AppLauncher(Browser* browser); |
| 188 virtual bool AcceleratorPressed(const views::Accelerator& accelerator); | 119 ~AppLauncher(); |
| 189 | 120 |
| 190 void AddTabWithURL(const GURL& url, PageTransition::Type transition); | 121 void AddTabWithURL(const GURL& url, PageTransition::Type transition); |
| 191 | 122 |
| 192 // The currently active browser. We use this to open urls. | 123 // The currently active browser. We use this to open urls. |
| 193 Browser* browser_; | 124 Browser* browser_; |
| 194 | 125 |
| 195 // The widget displaying the rwvh_. | 126 // The InfoBubble displaying the omnibox and app contents. |
| 196 views::WidgetGtk* popup_; | 127 InfoBubble* info_bubble_; |
| 197 | 128 |
| 198 // SiteInstance for the RenderViewHosts we create. | 129 // SiteInstance for the RenderViewHosts we create. |
| 199 SiteInstance* site_instance_; | 130 scoped_refptr<SiteInstance> site_instance_; |
| 200 | 131 |
| 201 // RenderViewHost for the contents. | 132 // RenderViewHost for the contents. |
| 202 RenderViewHost* contents_rvh_; | 133 RenderViewHost* contents_rvh_; |
| 203 | 134 |
| 204 // RenderWidgetHostView from the contents_rvh_. | 135 // RenderWidgetHostView from the contents_rvh_. |
| 205 RenderWidgetHostViewGtk* rwhv_; | 136 RenderWidgetHostView* rwhv_; |
| 206 | 137 |
| 207 // Handles creating the child TabContents. | 138 // Handles creating the child TabContents. |
| 208 RenderViewHostDelegateViewHelper helper_; | 139 RenderViewHostDelegateViewHelper helper_; |
| 209 | 140 |
| 210 // Delegate of the TabContents created by helper_. | 141 // Delegate of the TabContents created by helper_. |
| 211 TabContentsDelegateImpl tab_contents_delegate_; | 142 scoped_ptr<TabContentsDelegateImpl> tab_contents_delegate_; |
| 212 | 143 |
| 213 // TabContents created when the user clicks a link. | 144 // TabContents created when the user clicks a link. |
| 214 scoped_ptr<TabContents> pending_contents_; | 145 scoped_ptr<TabContents> pending_contents_; |
| 215 | 146 |
| 216 ScopedRunnableMethodFactory<AppLauncher> method_factory_; | 147 // The view with the navigation bar and render view, shown in the info-bubble. |
| 217 | 148 InfoBubbleContentsView* info_bubble_content_; |
| 218 // Container of the background, NavigationBar and Renderer. | |
| 219 views::View* top_container_; | |
| 220 | |
| 221 // Container of the NavigationBar and Renderer (shown in a bubble). | |
| 222 views::View* bubble_container_; | |
| 223 | |
| 224 // The navigation bar. Only shown in compact navigation bar mode. | |
| 225 NavigationBar* navigation_bar_; | |
| 226 | |
| 227 // The view containing the renderer view. | |
| 228 views::NativeViewHost* render_view_container_; | |
| 229 | |
| 230 // True if the popup has ever been shown. | |
| 231 bool has_shown_; | |
| 232 | 149 |
| 233 DISALLOW_COPY_AND_ASSIGN(AppLauncher); | 150 DISALLOW_COPY_AND_ASSIGN(AppLauncher); |
| 234 }; | 151 }; |
| 235 | 152 |
| 236 } // namespace chromeos | 153 #endif // CHROME_BROWSER_VIEWS_APP_LAUNCHER_H_ |
| 237 | |
| 238 #endif // CHROME_BROWSER_CHROMEOS_APP_LAUNCHER_H_ | |
| OLD | NEW |