diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 21:08:43 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 21:08:43 +0000 |
commit | df722f89f5ad78156319c5a0ff071641a205a78d (patch) | |
tree | 09e76fd83a7d1f05eb7084f75a5f10eaf8a58cde | |
parent | b13e3fb787be91e19c66df036a231a2e84a7d321 (diff) | |
download | chromium_src-df722f89f5ad78156319c5a0ff071641a205a78d.zip chromium_src-df722f89f5ad78156319c5a0ff071641a205a78d.tar.gz chromium_src-df722f89f5ad78156319c5a0ff071641a205a78d.tar.bz2 |
Implement location only display mode (used by popup windows).
This matches the pixel sizes on Windows. The location bar is
a couple pixels shorter and the font is a little smaller.
BUG=17580
Review URL: http://codereview.chromium.org/159303
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21578 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc | 11 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 47 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 59 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.h | 6 |
6 files changed, 96 insertions, 35 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index 4a2d975..d44f8f0 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -70,6 +70,7 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk( ToolbarModel* toolbar_model, Profile* profile, CommandUpdater* command_updater, + bool popup_window_mode, AutocompletePopupPositioner* popup_positioner) : text_view_(NULL), tag_table_(NULL), @@ -83,7 +84,7 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk( controller_(controller), toolbar_model_(toolbar_model), command_updater_(command_updater), - popup_window_mode_(false), // TODO(deanm) + popup_window_mode_(popup_window_mode), scheme_security_level_(ToolbarModel::NORMAL), selection_saved_(false), mark_set_handler_id_(0), @@ -125,9 +126,15 @@ void AutocompleteEditViewGtk::Init() { tag_table_ = gtk_text_tag_table_new(); text_buffer_ = gtk_text_buffer_new(tag_table_); text_view_ = gtk_text_view_new_with_buffer(text_buffer_); + if (popup_window_mode_) + gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view_), false); if (browser_defaults::kForceAutocompleteEditFontSize) { // Until we switch to vector graphics, force the font size. - gtk_util::ForceFontSizePixels(text_view_, 13.4); // 13.4px == 10pt @ 96dpi + const double kFontSize = 13.4; // 13.4px == 10pt @ 96dpi + // On Windows, popups have a font size 5/6 the size of non-popups. + const double kPopupWindowFontSize = kFontSize * 5.0 / 6.0; + gtk_util::ForceFontSizePixels(text_view_, + popup_window_mode_ ? kPopupWindowFontSize : kFontSize); } // Override the background color for now. http://crbug.com/12195 diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h index c0f6dd4..720dd00 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h @@ -42,6 +42,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView { ToolbarModel* toolbar_model, Profile* profile, CommandUpdater* command_updater, + bool popup_window_mode, AutocompletePopupPositioner* popup_positioner); ~AutocompleteEditViewGtk(); @@ -280,8 +281,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView { CommandUpdater* command_updater_; // When true, the location bar view is read only and also is has a slightly - // different presentation (font size / color). This is used for popups. - // TODO(deanm). + // different presentation (smaller font size). This is used for popups. bool popup_window_mode_; ToolbarModel::SecurityLevel scheme_security_level_; diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 8a03f5f..06200a6 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -47,6 +47,9 @@ namespace { // Height of the toolbar in pixels. const int kToolbarHeight = 37; +// Height of the toolbar in pixels when we only show the location bar. +const int kToolbarHeightLocationBarOnly = kToolbarHeight - 10; + // Interior spacing between toolbar widgets. const int kToolbarWidgetSpacing = 4; @@ -134,10 +137,13 @@ void BrowserToolbarGtk::Init(Profile* profile, toolbar_ = gtk_hbox_new(FALSE, kToolbarWidgetSpacing); gtk_container_add(GTK_CONTAINER(event_box_), toolbar_); - gtk_container_set_border_width(GTK_CONTAINER(toolbar_), 4); - // Demand we're always at least kToolbarHeight tall. - // -1 for width means "let GTK do its normal sizing". - gtk_widget_set_size_request(toolbar_, -1, kToolbarHeight); + gtk_container_set_border_width(GTK_CONTAINER(toolbar_), + ShouldOnlyShowLocation() ? 0 : 4); + // Force the height of the toolbar so we get the right amount of padding + // above and below the location bar. -1 for width means "let GTK do its + // normal sizing". + gtk_widget_set_size_request(toolbar_, -1, ShouldOnlyShowLocation() ? + kToolbarHeightLocationBarOnly : kToolbarHeight); g_signal_connect(toolbar_, "expose-event", G_CALLBACK(&OnToolbarExpose), this); @@ -176,7 +182,7 @@ void BrowserToolbarGtk::Init(Profile* profile, star_.reset(BuildStarButton(l10n_util::GetStringUTF8(IDS_TOOLTIP_STAR))); gtk_box_pack_start(GTK_BOX(location_hbox), star_->widget(), FALSE, FALSE, 0); - location_bar_->Init(); + location_bar_->Init(ShouldOnlyShowLocation()); gtk_box_pack_start(GTK_BOX(location_hbox), location_bar_->widget(), TRUE, TRUE, 0); @@ -185,7 +191,8 @@ void BrowserToolbarGtk::Init(Profile* profile, g_signal_connect(location_hbox, "expose-event", G_CALLBACK(OnLocationHboxExpose), this); - gtk_box_pack_start(GTK_BOX(toolbar_), location_hbox, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(toolbar_), location_hbox, TRUE, TRUE, + ShouldOnlyShowLocation() ? 1 : 0); // Group the menu buttons together in an hbox. GtkWidget* menus_hbox_ = gtk_hbox_new(FALSE, 0); @@ -221,12 +228,20 @@ void BrowserToolbarGtk::Init(Profile* profile, gtk_box_pack_start(GTK_BOX(toolbar_), menus_hbox_, FALSE, FALSE, 0); - gtk_widget_show_all(event_box_); - - if (show_home_button_.GetValue()) { - gtk_widget_show(home_->widget()); + if (ShouldOnlyShowLocation()) { + gtk_widget_show(event_box_); + gtk_widget_show(toolbar_); + gtk_widget_show_all(location_hbox); + gtk_widget_hide(star_->widget()); + gtk_widget_hide(go_->widget()); } else { - gtk_widget_hide(home_->widget()); + gtk_widget_show_all(event_box_); + + if (show_home_button_.GetValue()) { + gtk_widget_show(home_->widget()); + } else { + gtk_widget_hide(home_->widget()); + } } } @@ -318,7 +333,7 @@ void BrowserToolbarGtk::Observe(NotificationType type, if (type == NotificationType::PREF_CHANGED) { std::wstring* pref_name = Details<std::wstring>(details).ptr(); if (*pref_name == prefs::kShowHomeButton) { - if (show_home_button_.GetValue()) { + if (show_home_button_.GetValue() && !ShouldOnlyShowLocation()) { gtk_widget_show(home_->widget()); } else { gtk_widget_hide(home_->widget()); @@ -490,7 +505,8 @@ gboolean BrowserToolbarGtk::OnToolbarExpose(GtkWidget* widget, gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox, GdkEventExpose* e, BrowserToolbarGtk* toolbar) { - if (toolbar->theme_provider_->UseGtkTheme()) { + if (toolbar->theme_provider_->UseGtkTheme() && + !toolbar->ShouldOnlyShowLocation()) { // To get the proper look surrounding the location bar, we fake out the // theme engine into drawing a button. We fake out GTK by constructing a // box that's from the top left corner of the bookmark button to the bottom @@ -621,3 +637,8 @@ void BrowserToolbarGtk::OnPageAppMenuMoveCurrent(GtkWidget* menu, break; } } + +bool BrowserToolbarGtk::ShouldOnlyShowLocation() const { + // If we're a popup window, only show the location bar (omnibox). + return browser_->type() != Browser::TYPE_NORMAL; +} diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h index ebfdc34..945d06c 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.h +++ b/chrome/browser/gtk/browser_toolbar_gtk.h @@ -147,6 +147,10 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, GtkMenuDirectionType dir, BrowserToolbarGtk* toolbar); + // Sometimes we only want to show the location w/o the toolbar buttons (e.g., + // in a popup window). + bool ShouldOnlyShowLocation() const; + // Ninebox for the toolbar background scoped_ptr<NineBox> background_ninebox_; diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 503a476..01587ec 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -30,10 +30,11 @@ namespace { -// Top and bottom padding/margin // We are positioned with a little bit of extra space that we don't use now. const int kTopMargin = 1; const int kBottomMargin = 1; +const int kLeftMargin = 1; +const int kRightMargin = 1; // We draw a border on the top and bottom (but not on left or right). const int kBorderThickness = 1; @@ -112,7 +113,8 @@ LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater, popup_positioner_(popup_positioner), disposition_(CURRENT_TAB), transition_(PageTransition::TYPED), - first_run_bubble_(this) { + first_run_bubble_(this), + popup_window_mode_(false) { } LocationBarViewGtk::~LocationBarViewGtk() { @@ -120,11 +122,13 @@ LocationBarViewGtk::~LocationBarViewGtk() { hbox_.Destroy(); } -void LocationBarViewGtk::Init() { +void LocationBarViewGtk::Init(bool popup_window_mode) { + popup_window_mode_ = popup_window_mode; location_entry_.reset(new AutocompleteEditViewGtk(this, toolbar_model_, profile_, command_updater_, + popup_window_mode_, popup_positioner_)); location_entry_->Init(); @@ -176,10 +180,18 @@ void LocationBarViewGtk::Init() { // construction for with GTK themes and without. Doing that only on // construction was wrong, and I can't see a difference between the two ways // anyway... Investigate more later. - gtk_alignment_set_padding(GTK_ALIGNMENT(align), - kTopMargin + kBorderThickness, - kBottomMargin + kBorderThickness, - kEditLeftRightPadding, kEditLeftRightPadding); + if (popup_window_mode_) { + gtk_alignment_set_padding(GTK_ALIGNMENT(align), + kTopMargin + kBorderThickness, + kBottomMargin + kBorderThickness, + kEditLeftRightPadding + kBorderThickness, + kEditLeftRightPadding + kBorderThickness); + } else { + gtk_alignment_set_padding(GTK_ALIGNMENT(align), + kTopMargin + kBorderThickness, + kBottomMargin + kBorderThickness, + kEditLeftRightPadding, kEditLeftRightPadding); + } gtk_container_add(GTK_CONTAINER(align), location_entry_->widget()); gtk_box_pack_start(GTK_BOX(hbox_.get()), align, TRUE, TRUE, 0); @@ -389,7 +401,17 @@ gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget, // window, set a clip to make sure that we don't draw outside. gdk_gc_set_clip_rectangle(gc, &inner_rect); - // If we're not using GTK theming, draw our own border. + // Draw the background. + gdk_gc_set_rgb_fg_color(gc, + &kBackgroundColorByLevel[toolbar_model_->GetSchemeSecurityLevel()]); + gdk_draw_rectangle(drawable, gc, TRUE, + inner_rect.x, + inner_rect.y, + inner_rect.width, + inner_rect.height); + + // If we're not using GTK theming, draw our own border over the edge pixels + // of the background. if (!profile_ || !GtkThemeProvider::GetFrom(profile_)->UseGtkTheme()) { // Draw our 1px border. TODO(deanm): Maybe this would be cleaner as an @@ -405,17 +427,20 @@ gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget, inner_rect.y + inner_rect.height - kBorderThickness, inner_rect.width, kBorderThickness); + if (popup_window_mode_) { + gdk_draw_rectangle(drawable, gc, TRUE, + inner_rect.x, + inner_rect.y, + kBorderThickness, + inner_rect.height); + gdk_draw_rectangle(drawable, gc, TRUE, + inner_rect.x + inner_rect.width - kBorderThickness, + inner_rect.y, + kBorderThickness, + inner_rect.height); + } } - // Draw the background within the border. - gdk_gc_set_rgb_fg_color(gc, - &kBackgroundColorByLevel[toolbar_model_->GetSchemeSecurityLevel()]); - gdk_draw_rectangle(drawable, gc, TRUE, - inner_rect.x, - inner_rect.y + kBorderThickness, - inner_rect.width, - inner_rect.height - (kBorderThickness * 2)); - g_object_unref(gc); return FALSE; // Continue propagating the expose. diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h index f3cafd2..1ac1fa4 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.h +++ b/chrome/browser/gtk/location_bar_view_gtk.h @@ -35,7 +35,7 @@ class LocationBarViewGtk : public AutocompleteEditController, AutocompletePopupPositioner* popup_positioner); virtual ~LocationBarViewGtk(); - void Init(); + void Init(bool popup_window_mode); void SetProfile(Profile* profile); @@ -146,6 +146,10 @@ class LocationBarViewGtk : public AutocompleteEditController, // Used schedule a task for the first run info bubble. ScopedRunnableMethodFactory<LocationBarViewGtk> first_run_bubble_; + // When true, the location bar view is read only and also is has a slightly + // different presentation (font size / color). This is used for popups. + bool popup_window_mode_; + DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtk); }; |