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 #include "chrome/browser/views/app_launcher.h" | 5 #include "chrome/browser/views/app_launcher.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/task.h" | 14 #include "base/task.h" |
15 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 15 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
16 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 16 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
17 #include "chrome/browser/browser.h" | 17 #include "chrome/browser/browser.h" |
18 #include "chrome/browser/browser_window.h" | 18 #include "chrome/browser/browser_window.h" |
19 #include "chrome/browser/bubble_positioner.h" | |
20 #include "chrome/browser/in_process_webkit/webkit_context.h" | 19 #include "chrome/browser/in_process_webkit/webkit_context.h" |
21 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
22 #include "chrome/browser/renderer_host/render_view_host.h" | 21 #include "chrome/browser/renderer_host/render_view_host.h" |
23 #include "chrome/browser/renderer_host/render_view_host_factory.h" | 22 #include "chrome/browser/renderer_host/render_view_host_factory.h" |
24 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 23 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
25 #include "chrome/browser/renderer_host/site_instance.h" | 24 #include "chrome/browser/renderer_host/site_instance.h" |
26 #include "chrome/browser/renderer_preferences_util.h" | 25 #include "chrome/browser/renderer_preferences_util.h" |
27 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" | 26 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" |
28 #include "chrome/browser/tab_contents/tab_contents.h" | 27 #include "chrome/browser/tab_contents/tab_contents.h" |
29 #include "chrome/browser/views/info_bubble.h" | 28 #include "chrome/browser/views/info_bubble.h" |
(...skipping 17 matching lines...) Expand all Loading... |
47 namespace { | 46 namespace { |
48 | 47 |
49 // Padding & margins for the navigation entry. | 48 // Padding & margins for the navigation entry. |
50 const int kNavigationEntryPadding = 2; | 49 const int kNavigationEntryPadding = 2; |
51 const int kNavigationEntryXMargin = 3; | 50 const int kNavigationEntryXMargin = 3; |
52 const int kNavigationEntryYMargin = 1; | 51 const int kNavigationEntryYMargin = 1; |
53 | 52 |
54 // Padding between the navigation bar and the render view contents. | 53 // Padding between the navigation bar and the render view contents. |
55 const int kNavigationBarBottomPadding = 3; | 54 const int kNavigationBarBottomPadding = 3; |
56 | 55 |
57 // NavigationBar size. | 56 // NavigationBar constants. |
58 const int kNavigationBarHeight = 25; | 57 const int kNavigationBarHeight = 25; |
| 58 const int kNavigationBarBorderThickness = 1; |
59 | 59 |
60 // The delta applied to the default font size for the omnibox. | 60 // The delta applied to the default font size for the omnibox. |
61 const int kAutocompleteEditFontDelta = 3; | 61 const int kAutocompleteEditFontDelta = 3; |
62 | 62 |
63 // Command line switch for specifying url of the page. | 63 // Command line switch for specifying url of the page. |
64 const wchar_t kURLSwitch[] = L"main-menu-url"; | 64 const wchar_t kURLSwitch[] = L"main-menu-url"; |
65 | 65 |
66 // Returns the URL of the menu. | 66 // Returns the URL of the menu. |
67 static GURL GetMenuURL() { | 67 static GURL GetMenuURL() { |
68 std::wstring url_string = | 68 std::wstring url_string = |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 app_launcher_->Hide(); | 140 app_launcher_->Hide(); |
141 } | 141 } |
142 | 142 |
143 //////////////////////////////////////////////////////////////////////////////// | 143 //////////////////////////////////////////////////////////////////////////////// |
144 // NavigationBar | 144 // NavigationBar |
145 // | 145 // |
146 // A navigation bar that is shown in the app launcher in compact navigation bar | 146 // A navigation bar that is shown in the app launcher in compact navigation bar |
147 // mode. | 147 // mode. |
148 | 148 |
149 class NavigationBar : public views::View, | 149 class NavigationBar : public views::View, |
150 public AutocompleteEditController, | 150 public AutocompleteEditController { |
151 public BubblePositioner { | |
152 public: | 151 public: |
153 explicit NavigationBar(AppLauncher* app_launcher) | 152 explicit NavigationBar(AppLauncher* app_launcher) |
154 : app_launcher_(app_launcher), | 153 : app_launcher_(app_launcher), |
155 location_entry_view_(NULL) { | 154 location_entry_view_(NULL) { |
156 SetFocusable(true); | 155 SetFocusable(true); |
157 location_entry_view_ = new views::NativeViewHost; | 156 location_entry_view_ = new views::NativeViewHost; |
158 AddChildView(location_entry_view_); | 157 AddChildView(location_entry_view_); |
159 set_border(views::Border::CreateSolidBorder(1, SK_ColorGRAY)); | 158 set_border(views::Border::CreateSolidBorder(kNavigationBarBorderThickness, |
| 159 SK_ColorGRAY)); |
| 160 |
| 161 AddChildView(&popup_positioning_view_); |
| 162 popup_positioning_view_.SetVisible(false); |
| 163 popup_positioning_view_.set_parent_owned(false); |
160 } | 164 } |
161 | 165 |
162 virtual ~NavigationBar() { | 166 virtual ~NavigationBar() { |
163 if (location_entry_view_->native_view()) | 167 if (location_entry_view_->native_view()) |
164 location_entry_view_->Detach(); | 168 location_entry_view_->Detach(); |
165 } | 169 } |
166 | 170 |
167 // views::View overrides. | 171 // views::View overrides. |
168 virtual void Focus() { | 172 virtual void Focus() { |
169 location_entry_->SetFocus(); | 173 location_entry_->SetFocus(); |
170 location_entry_->SelectAll(true); | 174 location_entry_->SelectAll(true); |
171 } | 175 } |
172 | 176 |
173 virtual void ViewHierarchyChanged(bool is_add, | 177 virtual void ViewHierarchyChanged(bool is_add, |
174 views::View* parent, | 178 views::View* parent, |
175 views::View* child) { | 179 views::View* child) { |
176 if (!is_add || child != this) | 180 if (!is_add || child != this) |
177 return; | 181 return; |
178 | 182 |
179 DCHECK(!location_entry_.get()); | 183 DCHECK(!location_entry_.get()); |
180 | 184 |
181 Browser* browser = app_launcher_->browser(); | 185 Browser* browser = app_launcher_->browser(); |
182 #if defined (OS_WIN) | 186 #if defined (OS_WIN) |
183 gfx::Font font; | 187 gfx::Font font; |
184 font = font.DeriveFont(kAutocompleteEditFontDelta); | 188 font = font.DeriveFont(kAutocompleteEditFontDelta); |
185 AutocompleteEditViewWin* autocomplete_view = | 189 AutocompleteEditViewWin* autocomplete_view = |
186 new AutocompleteEditViewWin(font, this, browser->toolbar_model(), | 190 new AutocompleteEditViewWin(font, this, browser->toolbar_model(), |
187 this, GetWidget()->GetNativeView(), | 191 this, GetWidget()->GetNativeView(), |
188 browser->profile(), | 192 browser->profile(), |
189 browser->command_updater(), false, this); | 193 browser->command_updater(), false, |
| 194 &popup_positioning_view_); |
190 location_entry_.reset(autocomplete_view); | 195 location_entry_.reset(autocomplete_view); |
191 autocomplete_view->Update(NULL); | 196 autocomplete_view->Update(NULL); |
192 // The Update call above sets the autocomplete text to the current one in | 197 // The Update call above sets the autocomplete text to the current one in |
193 // the location bar, make sure to clear it. | 198 // the location bar, make sure to clear it. |
194 autocomplete_view->SetUserText(std::wstring()); | 199 autocomplete_view->SetUserText(std::wstring()); |
195 #elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS) | 200 #elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS) |
196 AutocompleteEditViewGtk* autocomplete_view = | 201 AutocompleteEditViewGtk* autocomplete_view = |
197 new AutocompleteEditViewGtk(this, browser->toolbar_model(), | 202 new AutocompleteEditViewGtk(this, browser->toolbar_model(), |
198 browser->profile(), | 203 browser->profile(), |
199 browser->command_updater(), false, this); | 204 browser->command_updater(), false, |
| 205 &popup_positioning_view_); |
200 autocomplete_view->Init(); | 206 autocomplete_view->Init(); |
201 gtk_widget_show_all(autocomplete_view->GetNativeView()); | 207 gtk_widget_show_all(autocomplete_view->GetNativeView()); |
202 gtk_widget_hide(autocomplete_view->GetNativeView()); | 208 gtk_widget_hide(autocomplete_view->GetNativeView()); |
203 location_entry_.reset(autocomplete_view); | 209 location_entry_.reset(autocomplete_view); |
204 #else | 210 #else |
205 NOTIMPLEMENTED(); | 211 NOTIMPLEMENTED(); |
206 #endif | 212 #endif |
207 location_entry_view_->set_focus_view(this); | 213 location_entry_view_->set_focus_view(this); |
208 location_entry_view_->Attach(location_entry_->GetNativeView()); | 214 location_entry_view_->Attach(location_entry_->GetNativeView()); |
209 } | 215 } |
210 | 216 |
211 virtual void Layout() { | 217 virtual void Layout() { |
212 gfx::Rect bounds = GetLocalBounds(false); | 218 gfx::Rect bounds = GetLocalBounds(false); |
213 location_entry_view_->SetBounds( | 219 location_entry_view_->SetBounds( |
214 bounds.x() + kNavigationEntryXMargin + kNavigationEntryPadding, | 220 bounds.x() + kNavigationEntryXMargin + kNavigationEntryPadding, |
215 bounds.y() + kNavigationEntryYMargin, | 221 bounds.y() + kNavigationEntryYMargin, |
216 bounds.width() - 2 * (kNavigationEntryPadding + | 222 bounds.width() - 2 * (kNavigationEntryPadding + |
217 kNavigationEntryXMargin), | 223 kNavigationEntryXMargin), |
218 bounds.height() - kNavigationEntryYMargin * 2); | 224 bounds.height() - kNavigationEntryYMargin * 2); |
219 } | |
220 | 225 |
221 // BubblePositioner implementation. | 226 gfx::Rect popup_positioning_bounds(bounds); |
222 virtual gfx::Rect GetLocationStackBounds() const { | 227 popup_positioning_bounds.Inset(0, -(kNavigationBarBorderThickness + 1)); |
223 gfx::Rect bounds = location_entry_view_->GetBounds( | 228 popup_positioning_view_.SetBounds(popup_positioning_bounds); |
224 views::View::APPLY_MIRRORING_TRANSFORMATION); | |
225 gfx::Point origin(bounds.x(), bounds.bottom() + kNavigationEntryPadding); | |
226 views::View::ConvertPointToScreen(this, &origin); | |
227 gfx::Rect rect = gfx::Rect(origin, gfx::Size(500, 0)); | |
228 if (UILayoutIsRightToLeft()) { | |
229 // Align the window to the right side of the entry view when | |
230 // UI is RTL mode. | |
231 rect.set_x(rect.x() - (rect.width() - location_entry_view_->width())); | |
232 } | |
233 return rect; | |
234 } | 229 } |
235 | 230 |
236 // AutocompleteController implementation. | 231 // AutocompleteController implementation. |
237 virtual void OnAutocompleteAccept(const GURL& url, | 232 virtual void OnAutocompleteAccept(const GURL& url, |
238 WindowOpenDisposition disposition, | 233 WindowOpenDisposition disposition, |
239 PageTransition::Type transition, | 234 PageTransition::Type transition, |
240 const GURL& alternate_nav_url) { | 235 const GURL& alternate_nav_url) { |
241 app_launcher_->AddTabWithURL(url, transition); | 236 app_launcher_->AddTabWithURL(url, transition); |
242 app_launcher_->Hide(); | 237 app_launcher_->Hide(); |
243 } | 238 } |
(...skipping 19 matching lines...) Expand all Loading... |
263 AppLauncher* app_launcher_; | 258 AppLauncher* app_launcher_; |
264 views::NativeViewHost* location_entry_view_; | 259 views::NativeViewHost* location_entry_view_; |
265 #if defined(OS_WIN) | 260 #if defined(OS_WIN) |
266 scoped_ptr<AutocompleteEditViewWin> location_entry_; | 261 scoped_ptr<AutocompleteEditViewWin> location_entry_; |
267 #elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS) | 262 #elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS) |
268 scoped_ptr<AutocompleteEditViewGtk> location_entry_; | 263 scoped_ptr<AutocompleteEditViewGtk> location_entry_; |
269 #else | 264 #else |
270 NOTIMPLEMENTED(); | 265 NOTIMPLEMENTED(); |
271 #endif | 266 #endif |
272 | 267 |
| 268 // This invisible view is provided to the popup in place of |this|, so the |
| 269 // popup can size itself against it using the same offsets it does with the |
| 270 // LocationBarView. |
| 271 views::View popup_positioning_view_; |
| 272 |
273 DISALLOW_COPY_AND_ASSIGN(NavigationBar); | 273 DISALLOW_COPY_AND_ASSIGN(NavigationBar); |
274 }; | 274 }; |
275 | 275 |
276 //////////////////////////////////////////////////////////////////////////////// | 276 //////////////////////////////////////////////////////////////////////////////// |
277 // InfoBubbleContentsView | 277 // InfoBubbleContentsView |
278 // | 278 // |
279 // The view that contains the navigation bar and render view. | 279 // The view that contains the navigation bar and render view. |
280 // It is displayed in an info-bubble. | 280 // It is displayed in an info-bubble. |
281 | 281 |
282 class InfoBubbleContentsView : public views::View { | 282 class InfoBubbleContentsView : public views::View { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 } | 518 } |
519 case chromeos::StatusAreaView::OPEN_TABS_ON_RIGHT: { | 519 case chromeos::StatusAreaView::OPEN_TABS_ON_RIGHT: { |
520 browser_->AddTabWithURL(url, GURL(), transition, true, -1, true, NULL); | 520 browser_->AddTabWithURL(url, GURL(), transition, true, -1, true, NULL); |
521 break; | 521 break; |
522 } | 522 } |
523 } | 523 } |
524 #else | 524 #else |
525 browser_->AddTabWithURL(url, GURL(), transition, true, -1, true, NULL); | 525 browser_->AddTabWithURL(url, GURL(), transition, true, -1, true, NULL); |
526 #endif | 526 #endif |
527 } | 527 } |
OLD | NEW |