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 #include "chrome/browser/gtk/browser_toolbar_gtk.h" | 5 #include "chrome/browser/gtk/browser_toolbar_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 #include <X11/XF86keysym.h> | 8 #include <X11/XF86keysym.h> |
9 | 9 |
10 #include "app/gtk_dnd_util.h" | 10 #include "app/gtk_dnd_util.h" |
(...skipping 43 matching lines...) Loading... |
54 | 54 |
55 // Exterior padding on left/right of toolbar. | 55 // Exterior padding on left/right of toolbar. |
56 const int kLeftRightPadding = 2; | 56 const int kLeftRightPadding = 2; |
57 | 57 |
58 // Height of the toolbar in pixels when we only show the location bar. | 58 // Height of the toolbar in pixels when we only show the location bar. |
59 const int kToolbarHeightLocationBarOnly = kToolbarHeight - 2; | 59 const int kToolbarHeightLocationBarOnly = kToolbarHeight - 2; |
60 | 60 |
61 // Interior spacing between toolbar widgets. | 61 // Interior spacing between toolbar widgets. |
62 const int kToolbarWidgetSpacing = 4; | 62 const int kToolbarWidgetSpacing = 4; |
63 | 63 |
64 // The amount of space between the bottom of the star and the top of the | |
65 // Omnibox results popup window. We want a two pixel space between the bottom | |
66 // and the results, but have some extra space below the buttons already. | |
67 const int kPopupTopMargin = 0; | |
68 | |
69 // Space between the edge of the star/go button and the popup frame. We want | |
70 // to leave 1 pixel on both side here so that the borders line up. | |
71 const int kPopupLeftRightMargin = 1; | |
72 | |
73 // The color used as the base[] color of the location entry during a secure | 64 // The color used as the base[] color of the location entry during a secure |
74 // connection. | 65 // connection. |
75 const GdkColor kSecureColor = GDK_COLOR_RGB(255, 245, 195); | 66 const GdkColor kSecureColor = GDK_COLOR_RGB(255, 245, 195); |
76 | 67 |
77 } // namespace | 68 } // namespace |
78 | 69 |
79 // BrowserToolbarGtk, public --------------------------------------------------- | 70 // BrowserToolbarGtk, public --------------------------------------------------- |
80 | 71 |
81 BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) | 72 BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) |
82 : toolbar_(NULL), | 73 : toolbar_(NULL), |
(...skipping 335 matching lines...) Loading... |
418 | 409 |
419 profile_ = profile; | 410 profile_ = profile; |
420 location_bar_->SetProfile(profile); | 411 location_bar_->SetProfile(profile); |
421 } | 412 } |
422 | 413 |
423 void BrowserToolbarGtk::UpdateTabContents(TabContents* contents, | 414 void BrowserToolbarGtk::UpdateTabContents(TabContents* contents, |
424 bool should_restore_state) { | 415 bool should_restore_state) { |
425 location_bar_->Update(should_restore_state ? contents : NULL); | 416 location_bar_->Update(should_restore_state ? contents : NULL); |
426 } | 417 } |
427 | 418 |
428 gfx::Rect BrowserToolbarGtk::GetPopupBounds() const { | 419 gfx::Rect BrowserToolbarGtk::GetLocationStackBounds() const { |
| 420 // The number of pixels from the left or right edges of the location stack to |
| 421 // "just inside the visible borders". When the omnibox bubble contents are |
| 422 // aligned with this, the visible borders tacked on to the outsides will line |
| 423 // up with the visible borders on the location stack. |
| 424 const int kLocationStackEdgeWidth = 1; |
| 425 |
429 GtkWidget* left; | 426 GtkWidget* left; |
430 GtkWidget* right; | 427 GtkWidget* right; |
431 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { | 428 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { |
432 left = go_->widget(); | 429 left = go_->widget(); |
433 right = star_->widget(); | 430 right = star_->widget(); |
434 } else { | 431 } else { |
435 left = star_->widget(); | 432 left = star_->widget(); |
436 right = go_->widget(); | 433 right = go_->widget(); |
437 } | 434 } |
438 | 435 |
439 gint origin_x, origin_y; | 436 gint origin_x, origin_y; |
440 DCHECK_EQ(left->window, right->window); | 437 DCHECK_EQ(left->window, right->window); |
441 gdk_window_get_origin(left->window, &origin_x, &origin_y); | 438 gdk_window_get_origin(left->window, &origin_x, &origin_y); |
442 | 439 |
443 gint right_x = origin_x + right->allocation.x + right->allocation.width; | 440 gint right_x = origin_x + right->allocation.x + right->allocation.width; |
444 | |
445 gint left_x = origin_x + left->allocation.x; | 441 gint left_x = origin_x + left->allocation.x; |
446 | |
447 // Bottom edge. | |
448 gint left_y = origin_y + left->allocation.y + left->allocation.height; | |
449 | |
450 DCHECK_LE(left_x, right_x); | 442 DCHECK_LE(left_x, right_x); |
451 | 443 |
452 return gfx::Rect(left_x + kPopupLeftRightMargin, left_y + kPopupTopMargin, | 444 gfx::Rect stack_bounds(left_x, origin_y + left->allocation.y, |
453 right_x - left_x - (2 * kPopupLeftRightMargin), 0); | 445 right_x - left_x, left->allocation.height); |
| 446 // Inset the bounds to just inside the visible edges (see comment above). |
| 447 stack_bounds.Inset(kLocationStackEdgeWidth, 0); |
| 448 return stack_bounds; |
454 } | 449 } |
455 | 450 |
456 // BrowserToolbarGtk, private -------------------------------------------------- | 451 // BrowserToolbarGtk, private -------------------------------------------------- |
457 | 452 |
458 CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton( | 453 CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton( |
459 int normal_id, int active_id, int highlight_id, int depressed_id, | 454 int normal_id, int active_id, int highlight_id, int depressed_id, |
460 const std::string& localized_tooltip, const char* stock_id) { | 455 const std::string& localized_tooltip, const char* stock_id) { |
461 CustomDrawButton* button = new CustomDrawButton( | 456 CustomDrawButton* button = new CustomDrawButton( |
462 GtkThemeProvider::GetFrom(profile_), | 457 GtkThemeProvider::GetFrom(profile_), |
463 normal_id, active_id, highlight_id, depressed_id, stock_id, | 458 normal_id, active_id, highlight_id, depressed_id, stock_id, |
(...skipping 236 matching lines...) Loading... |
700 menu->PopupAsFromKeyEvent(button); | 695 menu->PopupAsFromKeyEvent(button); |
701 menu_bar_helper_.MenuStartedShowing(button, menu->widget()); | 696 menu_bar_helper_.MenuStartedShowing(button, menu->widget()); |
702 } | 697 } |
703 | 698 |
704 void BrowserToolbarGtk::PopupForButtonNextTo(GtkWidget* button, | 699 void BrowserToolbarGtk::PopupForButtonNextTo(GtkWidget* button, |
705 GtkMenuDirectionType dir) { | 700 GtkMenuDirectionType dir) { |
706 GtkWidget* other_button = button == page_menu_button_.get() ? | 701 GtkWidget* other_button = button == page_menu_button_.get() ? |
707 app_menu_button_.get() : page_menu_button_.get(); | 702 app_menu_button_.get() : page_menu_button_.get(); |
708 PopupForButton(other_button); | 703 PopupForButton(other_button); |
709 } | 704 } |
OLD | NEW |