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