OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_MAIN_MENU_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_MAIN_MENU_H_ |
6 #define CHROME_BROWSER_CHROMEOS_MAIN_MENU_H_ | 6 #define CHROME_BROWSER_CHROMEOS_MAIN_MENU_H_ |
7 | 7 |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
| 10 #include "base/scoped_ptr.h" |
10 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 11 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 12 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" |
| 13 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
11 | 14 |
12 class Browser; | 15 class Browser; |
13 class RenderWidgetHostViewGtk; | 16 class RenderWidgetHostViewGtk; |
14 class SiteInstance; | 17 class SiteInstance; |
15 | 18 |
16 namespace views { | 19 namespace views { |
17 class Widget; | 20 class Widget; |
18 } | 21 } |
19 | 22 |
20 // MainMenu manages showing the main menu. The menu is currently an HTML page. | 23 // MainMenu manages showing the main menu. The menu is currently an HTML page. |
21 // When the user clicks a link on the page a new tab is added to the current | 24 // When the user clicks a link on the page a new tab is added to the current |
22 // browser and the menu is hidden. | 25 // browser and the menu is hidden. |
23 // | 26 // |
24 // To show the menu invoke Show. | 27 // To show the menu invoke Show. |
25 // | 28 // |
26 // MainMenu creates a RenderViewHost and corresponding RenderWidgetHostView | 29 // MainMenu creates a RenderViewHost and corresponding RenderWidgetHostView |
27 // to display the html page. MainMenu acts as the RenderViewHostDelegate for | 30 // to display the html page. MainMenu acts as the RenderViewHostDelegate for |
28 // the RenderViewHost. Additionally when the user clicks a link a new window | 31 // the RenderViewHost. Clicking on a link results in creating a new |
29 // is created (child_rvh_). MainMenu is set as the RenderViewHostDelegate of | 32 // TabContents (assigned to pending_contents_). One of two things can then |
30 // the child_rvh_ so that it can receive the request to open the url | 33 // happen: |
31 // (RequestOpenURL). | 34 // . If the page is a popup (ShowCreatedWindow passed NEW_POPUP), the |
| 35 // TabContents is added to the Browser. |
| 36 // . If the page requests a URL to be open (OpenURLFromTab), OpenURL is |
| 37 // invoked on the browser. |
32 // | 38 // |
33 // When a new url is opened, or the user clicks outsides the bounds of the | 39 // When a new url is opened, or the user clicks outsides the bounds of the |
34 // widget the menu is closed. | 40 // widget the menu is closed. |
35 // | 41 // |
36 // MainMenu manages its own lifetime. | 42 // MainMenu manages its own lifetime. In some cases deletion is delayed because |
| 43 // the callers can't deal with being deleted while servicing a message from |
| 44 // the renderer. |
37 class MainMenu : public RenderViewHostDelegate, | 45 class MainMenu : public RenderViewHostDelegate, |
38 public RenderViewHostDelegate::View { | 46 public RenderViewHostDelegate::View { |
39 public: | 47 public: |
40 // Shows the menu. | 48 // Shows the menu. |
41 static void Show(Browser* browser); | 49 static void Show(Browser* browser); |
42 | 50 |
43 private: | |
44 explicit MainMenu(Browser* browser); | |
45 ~MainMenu(); | 51 ~MainMenu(); |
46 | 52 |
| 53 private: |
| 54 // TabContentsDelegate and RenderViewHostDelegate::View have some methods |
| 55 // in common (with differing signatures). The TabContentsDelegate methods are |
| 56 // implemented by this class. |
| 57 class TabContentsDelegateImpl : public TabContentsDelegate { |
| 58 public: |
| 59 explicit TabContentsDelegateImpl(MainMenu* menu) : menu_(menu) {} |
| 60 |
| 61 // TabContentsDelegate. |
| 62 virtual void OpenURLFromTab(TabContents* source, |
| 63 const GURL& url, const GURL& referrer, |
| 64 WindowOpenDisposition disposition, |
| 65 PageTransition::Type transition); |
| 66 virtual void NavigationStateChanged(const TabContents* source, |
| 67 unsigned changed_flags) {} |
| 68 virtual void AddNewContents(TabContents* source, |
| 69 TabContents* new_contents, |
| 70 WindowOpenDisposition disposition, |
| 71 const gfx::Rect& initial_pos, |
| 72 bool user_gesture) {} |
| 73 virtual void ActivateContents(TabContents* contents) {} |
| 74 virtual void LoadingStateChanged(TabContents* source) {} |
| 75 virtual void CloseContents(TabContents* source) {} |
| 76 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} |
| 77 virtual bool IsPopup(TabContents* source) { return false; } |
| 78 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {} |
| 79 virtual void URLStarredChanged(TabContents* source, bool starred) {} |
| 80 virtual void UpdateTargetURL(TabContents* source, const GURL& url) {} |
| 81 |
| 82 private: |
| 83 MainMenu* menu_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(TabContentsDelegateImpl); |
| 86 }; |
| 87 |
| 88 friend class TabContentsDelegateImpl; |
| 89 |
| 90 explicit MainMenu(Browser* browser); |
| 91 |
47 void ShowImpl(); | 92 void ShowImpl(); |
48 | 93 |
| 94 // Does cleanup before deletion. If |now| is true delete is invoked |
| 95 // immediately, otherwise deletion occurs after a delay. See description |
| 96 // above class as to why we need to delay deletion in some situations. |
| 97 void Delete(bool now); |
| 98 |
49 // Callback from button presses on the render widget host view. Clicks | 99 // Callback from button presses on the render widget host view. Clicks |
50 // outside the widget resulting in closing the menu. | 100 // outside the widget resulting in closing the menu. |
51 static gboolean CallButtonPressEvent(GtkWidget* widget, | 101 static gboolean CallButtonPressEvent(GtkWidget* widget, |
52 GdkEventButton* event, | 102 GdkEventButton* event, |
53 MainMenu* menu) { | 103 MainMenu* menu); |
54 return menu->OnButtonPressEvent(widget, event); | |
55 } | |
56 gboolean OnButtonPressEvent(GtkWidget* widget, | 104 gboolean OnButtonPressEvent(GtkWidget* widget, |
57 GdkEventButton* event); | 105 GdkEventButton* event); |
58 | 106 |
59 // RenderViewHostDelegate overrides. | 107 // RenderViewHostDelegate overrides. |
60 virtual int GetBrowserWindowID() const { | 108 virtual int GetBrowserWindowID() const { |
61 return -1; | 109 return -1; |
62 } | 110 } |
63 virtual ViewType::Type GetRenderViewType() const { | 111 virtual ViewType::Type GetRenderViewType() const { |
64 return ViewType::INVALID; | 112 return ViewType::INVALID; |
65 } | 113 } |
66 virtual RenderViewHostDelegate::View* GetViewDelegate() { | 114 virtual RenderViewHostDelegate::View* GetViewDelegate() { |
67 return this; | 115 return this; |
68 } | 116 } |
69 virtual void RequestOpenURL(const GURL& url, | |
70 const GURL& referrer, | |
71 WindowOpenDisposition disposition); | |
72 | 117 |
73 // RenderViewHostDelegate::View overrides. | 118 // RenderViewHostDelegate::View overrides. |
74 virtual void CreateNewWindow(int route_id, | 119 virtual void CreateNewWindow(int route_id, |
75 base::WaitableEvent* modal_dialog_event); | 120 base::WaitableEvent* modal_dialog_event); |
76 virtual void CreateNewWidget(int route_id, bool activatable) {} | 121 virtual void CreateNewWidget(int route_id, bool activatable) {} |
77 virtual void ShowCreatedWindow(int route_id, | 122 virtual void ShowCreatedWindow(int route_id, |
78 WindowOpenDisposition disposition, | 123 WindowOpenDisposition disposition, |
79 const gfx::Rect& initial_pos, | 124 const gfx::Rect& initial_pos, |
80 bool user_gesture, | 125 bool user_gesture, |
81 const GURL& creator_url) {} | 126 const GURL& creator_url); |
82 virtual void ShowCreatedWidget(int route_id, | 127 virtual void ShowCreatedWidget(int route_id, |
83 const gfx::Rect& initial_pos) {} | 128 const gfx::Rect& initial_pos) {} |
84 virtual void ShowContextMenu(const ContextMenuParams& params) {} | 129 virtual void ShowContextMenu(const ContextMenuParams& params) {} |
85 virtual void StartDragging(const WebDropData& drop_data, | 130 virtual void StartDragging(const WebDropData& drop_data, |
86 WebKit::WebDragOperationsMask allowed_ops) {} | 131 WebKit::WebDragOperationsMask allowed_ops) {} |
87 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} | 132 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} |
88 virtual void GotFocus() {} | 133 virtual void GotFocus() {} |
89 virtual void TakeFocus(bool reverse) {} | 134 virtual void TakeFocus(bool reverse) {} |
90 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} | 135 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} |
91 virtual void HandleMouseEvent() {} | 136 virtual void HandleMouseEvent() {} |
92 virtual void HandleMouseLeave() {} | 137 virtual void HandleMouseLeave() {} |
93 virtual void UpdatePreferredWidth(int pref_width) {} | 138 virtual void UpdatePreferredWidth(int pref_width) {} |
94 | 139 |
95 // The currently active browser. We use this to open urls. | 140 // The currently active browser. We use this to open urls. |
96 Browser* browser_; | 141 Browser* browser_; |
97 | 142 |
98 // The widget displaying the rwvh_. | 143 // The widget displaying the rwvh_. |
99 views::Widget* popup_; | 144 views::Widget* popup_; |
100 | 145 |
101 // SiteInstance for the RenderViewHosts we create. | 146 // SiteInstance for the RenderViewHosts we create. |
102 SiteInstance* site_instance_; | 147 SiteInstance* site_instance_; |
103 | 148 |
104 // RenderViewHost for the menu. | 149 // RenderViewHost for the menu. |
105 RenderViewHost* menu_rvh_; | 150 RenderViewHost* menu_rvh_; |
106 | 151 |
107 // RenderWidgetHostView from the menu_rvh_. | 152 // RenderWidgetHostView from the menu_rvh_. |
108 RenderWidgetHostViewGtk* rwhv_; | 153 RenderWidgetHostViewGtk* rwhv_; |
109 | 154 |
110 // If the user clicks an item in the menu a child RenderViewHost is opened. | 155 // Handles creating the child TabContents. |
111 // This is that child. | 156 RenderViewHostDelegateViewHelper helper_; |
112 RenderViewHost* child_rvh_; | 157 |
| 158 // Delegate of the TabContents created by helper_. |
| 159 TabContentsDelegateImpl tab_contents_delegate_; |
| 160 |
| 161 // TabContents created when the user clicks a link. |
| 162 scoped_ptr<TabContents> pending_contents_; |
113 | 163 |
114 DISALLOW_COPY_AND_ASSIGN(MainMenu); | 164 DISALLOW_COPY_AND_ASSIGN(MainMenu); |
115 }; | 165 }; |
116 | 166 |
117 #endif // CHROME_BROWSER_CHROMEOS_CHROMEOS_VERSION_LOADER_H_ | 167 #endif // CHROME_BROWSER_CHROMEOS_CHROMEOS_VERSION_LOADER_H_ |
OLD | NEW |