diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-19 19:01:14 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-19 19:01:14 +0000 |
commit | eed084d901efe457300e673972a0369406bd5e66 (patch) | |
tree | 82f94f52879937ded20a1fc7932bfbc300e408bf /chrome/browser | |
parent | b8f41a197500eb0d6fbff3e8f1216d99a49b7d07 (diff) | |
download | chromium_src-eed084d901efe457300e673972a0369406bd5e66.zip chromium_src-eed084d901efe457300e673972a0369406bd5e66.tar.gz chromium_src-eed084d901efe457300e673972a0369406bd5e66.tar.bz2 |
SSL UI changes, Windows, code side (images are separate).
* Remove "Type to search" hint
* Remove "Untrusted website" label
* Add EV cert bubble, make it function like a location icon for clicks/drags
* Modify spacing for EV/tab-to-search bubbles to keep icons and text aligned with dropdown
* Change non-EV HTTPS coloring from blue to green
Mac and Linux should compile, but only some of the above changes have been made for them. Specifically, there is no EV cert bubble, the non-EV scheme color isn't changed, and the icon/text alignment in the tab-to-search bubble hasn't been touched.
BUG=41481
TEST=paypal.com should generate a bubble around the lock and cert holder name, which responds to clicks and drags like the location icon would
Review URL: http://codereview.chromium.org/1585043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit.cc | 25 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit.h | 21 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc | 5 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_mac.mm | 5 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_win.cc | 17 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_popup_model.cc | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/location_bar_view_mac.h | 1 | ||||
-rw-r--r-- | chrome/browser/cocoa/location_bar_view_mac.mm | 36 | ||||
-rw-r--r-- | chrome/browser/cocoa/location_bar_view_mac_unittest.mm | 35 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 57 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.h | 13 | ||||
-rw-r--r-- | chrome/browser/toolbar_model.cc | 34 | ||||
-rw-r--r-- | chrome/browser/toolbar_model.h | 6 | ||||
-rw-r--r-- | chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc | 24 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 368 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.h | 120 |
16 files changed, 364 insertions, 407 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index 22c6802..9b0aefb 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -44,7 +44,6 @@ AutocompleteEditModel::AutocompleteEditModel( control_key_state_(UP), is_keyword_hint_(false), keyword_ui_state_(NORMAL), - show_search_hint_(true), paste_and_go_transition_(PageTransition::TYPED), profile_(profile) { } @@ -81,7 +80,7 @@ const AutocompleteEditModel::State } return State(user_input_in_progress_, user_text_, keyword_, is_keyword_hint_, - keyword_ui_state_, show_search_hint_); + keyword_ui_state_); } void AutocompleteEditModel::RestoreState(const State& state) { @@ -92,7 +91,6 @@ void AutocompleteEditModel::RestoreState(const State& state) { keyword_ = state.keyword; is_keyword_hint_ = state.is_keyword_hint; keyword_ui_state_ = state.keyword_ui_state; - show_search_hint_ = state.show_search_hint; view_->SetUserText(state.user_text, DisplayTextFromUserText(state.user_text), false); } @@ -182,7 +180,6 @@ void AutocompleteEditModel::Revert() { keyword_.clear(); is_keyword_hint_ = false; keyword_ui_state_ = NORMAL; - show_search_hint_ = permanent_text_.empty(); has_temporary_text_ = false; view_->SetWindowTextAndCaretPos(permanent_text_, has_focus_ ? permanent_text_.length() : 0); @@ -412,24 +409,13 @@ void AutocompleteEditModel::OnPopupDataChanged( const std::wstring& text, GURL* destination_for_temporary_text_change, const std::wstring& keyword, - bool is_keyword_hint, - AutocompleteMatch::Type type) { - // We don't want to show the search hint if we're showing a keyword hint or - // selected keyword, or (subtle!) if we would be showing a selected keyword - // but for keyword_ui_state_ == NO_KEYWORD. - const bool show_search_hint = keyword.empty() && - ((type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED) || - (type == AutocompleteMatch::SEARCH_HISTORY) || - (type == AutocompleteMatch::SEARCH_SUGGEST)); - + bool is_keyword_hint) { // Update keyword/hint-related local state. bool keyword_state_changed = (keyword_ != keyword) || - ((is_keyword_hint_ != is_keyword_hint) && !keyword.empty()) || - (show_search_hint_ != show_search_hint); + ((is_keyword_hint_ != is_keyword_hint) && !keyword.empty()); if (keyword_state_changed) { keyword_ = keyword; is_keyword_hint_ = is_keyword_hint; - show_search_hint_ = show_search_hint; } // Handle changes to temporary text. @@ -547,7 +533,6 @@ void AutocompleteEditModel::Observe(NotificationType type, std::wstring inline_autocomplete_text; std::wstring keyword; bool is_keyword_hint = false; - AutocompleteMatch::Type match_type = AutocompleteMatch::SEARCH_WHAT_YOU_TYPED; const AutocompleteResult* result = Details<const AutocompleteResult>(details).ptr(); const AutocompleteResult::const_iterator match(result->default_match()); @@ -564,11 +549,9 @@ void AutocompleteEditModel::Observe(NotificationType type, // the OS DNS cache could suffer eviction problems for minimal gain. is_keyword_hint = popup_->GetKeywordForMatch(*match, &keyword); - match_type = match->type; } - OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, is_keyword_hint, - match_type); + OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, is_keyword_hint); } void AutocompleteEditModel::InternalSetUserText(const std::wstring& text) { diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h index 96a86c7..9f4e973 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.h +++ b/chrome/browser/autocomplete/autocomplete_edit.h @@ -83,14 +83,12 @@ class AutocompleteEditModel : public NotificationObserver { const std::wstring& user_text, const std::wstring& keyword, bool is_keyword_hint, - KeywordUIState keyword_ui_state, - bool show_search_hint) + KeywordUIState keyword_ui_state) : user_input_in_progress(user_input_in_progress), user_text(user_text), keyword(keyword), is_keyword_hint(is_keyword_hint), - keyword_ui_state(keyword_ui_state), - show_search_hint(show_search_hint) { + keyword_ui_state(keyword_ui_state) { } bool user_input_in_progress; @@ -98,7 +96,6 @@ class AutocompleteEditModel : public NotificationObserver { const std::wstring keyword; const bool is_keyword_hint; const KeywordUIState keyword_ui_state; - const bool show_search_hint; }; AutocompleteEditModel(AutocompleteEditView* view, @@ -223,10 +220,6 @@ class AutocompleteEditModel : public NotificationObserver { // currently visible in the edit. void ClearKeyword(const std::wstring& visible_text); - // True if we should show the "Type to search" hint (see comments on - // show_search_hint_). - bool show_search_hint() const { return show_search_hint_; } - // Returns true if a query to an autocomplete provider is currently // in progress. This logic should in the future live in // AutocompleteController but resides here for now. This method is used by @@ -272,15 +265,11 @@ class AutocompleteEditModel : public NotificationObserver { // |keyword| is the keyword to show a hint for if |is_keyword_hint| is true, // or the currently selected keyword if |is_keyword_hint| is false (see // comments on keyword_ and is_keyword_hint_). - // |type| is the type of match selected; this is used to determine whether - // we can show the "Type to search" hint (see comments on - // show_search_hint_). void OnPopupDataChanged( const std::wstring& text, GURL* destination_for_temporary_text_change, const std::wstring& keyword, - bool is_keyword_hint, - AutocompleteMatch::Type type); + bool is_keyword_hint); // Called by the AutocompleteEditView after something changes, with details // about what state changes occured. Updates internal state, updates the @@ -432,10 +421,6 @@ class AutocompleteEditModel : public NotificationObserver { // See KeywordUIState enum. KeywordUIState keyword_ui_state_; - // True when it's safe to show a "Type to search" hint to the user (when the - // edit is empty, or the user is in the process of searching). - bool show_search_hint_; - // Paste And Go-related state. See CanPasteAndGo(). mutable GURL paste_and_go_url_; mutable PageTransition::Type paste_and_go_transition_; diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index ea49b8e..563b18e 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -127,7 +127,7 @@ void ClipboardSelectionCleared(GtkClipboard* clipboard, if (!gtk_text_iter_equal(&insert, &selection_bound)) { gtk_text_buffer_move_mark(buffer, - gtk_text_buffer_get_selection_bound (buffer), + gtk_text_buffer_get_selection_bound(buffer), &insert); } } @@ -423,7 +423,8 @@ std::wstring AutocompleteEditViewGtk::GetText() const { } bool AutocompleteEditViewGtk::IsEditingOrEmpty() const { - return (model_->user_input_in_progress() || model_->show_search_hint()); + return model_->user_input_in_progress() || + (gtk_text_buffer_get_char_count(text_buffer_) == 0); } int AutocompleteEditViewGtk::GetIcon() const { diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm index 70239ab..61ff69dd 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm @@ -138,8 +138,6 @@ NSImage* AutocompleteEditViewMac::ImageForResource(int resource_id) { case IDR_OMNIBOX_MORE: image_name = @"omnibox_more.pdf"; break; // Values from |ToolbarModel::GetIcon()|. - case IDR_OMNIBOX_HTTPS_GREEN: - image_name = @"omnibox_https_green.pdf"; break; case IDR_OMNIBOX_HTTPS_VALID: image_name = @"omnibox_https_valid.pdf"; break; case IDR_OMNIBOX_HTTPS_WARNING: @@ -308,7 +306,8 @@ std::wstring AutocompleteEditViewMac::GetText() const { } bool AutocompleteEditViewMac::IsEditingOrEmpty() const { - return (model_->user_input_in_progress() || model_->show_search_hint()); + return model_->user_input_in_progress() || + ([[field_ stringValue] length] == 0); } int AutocompleteEditViewMac::GetIcon() const { diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index 45386c4..5a0632f 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -599,7 +599,7 @@ std::wstring AutocompleteEditViewWin::GetText() const { } bool AutocompleteEditViewWin::IsEditingOrEmpty() const { - return (model_->user_input_in_progress() || model_->show_search_hint()); + return model_->user_input_in_progress() || (GetTextLength() == 0); } int AutocompleteEditViewWin::GetIcon() const { @@ -1372,15 +1372,6 @@ void AutocompleteEditViewWin::OnKillFocus(HWND focus_wnd) { ScopedFreeze freeze(this, GetTextObjectModel()); DefWindowProc(WM_KILLFOCUS, reinterpret_cast<WPARAM>(focus_wnd), 0); - // Hide the "Type to search" hint if necessary. We do this after calling - // DefWindowProc() because processing the resulting IME messages may notify - // the controller that input is in progress, which could cause the visible - // hints to change. (I don't know if there's a real scenario where they - // actually do change, but this is safest.) - if (model_->show_search_hint() || - (model_->is_keyword_hint() && !model_->keyword().empty())) - controller_->OnChanged(); - // Cancel any user selection and scroll the text back to the beginning of the // URL. We have to do this after calling DefWindowProc() because otherwise // an in-progress IME composition will be completed at the new caret position, @@ -1690,12 +1681,6 @@ void AutocompleteEditViewWin::OnSetFocus(HWND focus_wnd) { model_->OnSetFocus(GetKeyState(VK_CONTROL) < 0); - // Notify controller if it needs to show hint UI of some kind. - ScopedFreeze freeze(this, GetTextObjectModel()); - if (model_->show_search_hint() || - (model_->is_keyword_hint() && !model_->keyword().empty())) - controller_->OnChanged(); - // Restore saved selection if available. if (saved_selection_for_focus_change_.cpMin != -1) { SetSelectionRange(saved_selection_for_focus_change_); diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc index 5939b64..009cc0b 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_model.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc @@ -129,10 +129,10 @@ void AutocompletePopupModel::SetSelectedLine(size_t line, match.fill_into_edit.substr(match.inline_autocomplete_offset); } edit_model_->OnPopupDataChanged(inline_autocomplete_text, NULL, - keyword, is_keyword_hint, match.type); + keyword, is_keyword_hint); } else { edit_model_->OnPopupDataChanged(match.fill_into_edit, ¤t_destination, - keyword, is_keyword_hint, match.type); + keyword, is_keyword_hint); } // Repaint old and new selected lines immediately, so that the edit doesn't diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h index c4fdcfd..66584f0 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.h +++ b/chrome/browser/cocoa/location_bar_view_mac.h @@ -132,7 +132,6 @@ class LocationBarViewMac : public AutocompleteEditController, const std::wstring& keyword, const std::wstring& short_name, const bool is_keyword_hint, - const bool show_search_hint, NSImage* image); // Overridden from NotificationObserver. diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm index ef2ce52..6e33130 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar_view_mac.mm @@ -260,7 +260,6 @@ void LocationBarViewMac::OnChangedImpl(AutocompleteTextField* field, const std::wstring& keyword, const std::wstring& short_name, const bool is_keyword_hint, - const bool show_search_hint, NSImage* image) { AutocompleteTextFieldCell* cell = [field autocompleteTextFieldCell]; const CGFloat availableWidth([field availableDecorationWidth]); @@ -306,12 +305,6 @@ void LocationBarViewMac::OnChangedImpl(AutocompleteTextField* field, [cell setKeywordHintPrefix:prefix image:image suffix:suffix availableWidth:availableWidth]; - } else if (show_search_hint) { - // Show a search hint right-justified in the field if there is no - // keyword. - const std::wstring hint(l10n_util::GetString(IDS_OMNIBOX_EMPTY_TEXT)); - [cell setSearchHintString:base::SysWideToNSString(hint) - availableWidth:availableWidth]; } else { // Nothing interesting to show, plain old text field. [cell clearKeywordAndHint]; @@ -338,7 +331,6 @@ void LocationBarViewMac::OnChanged() { keyword, short_name, edit_view_->model()->is_keyword_hint(), - edit_view_->model()->show_search_hint(), GetTabButtonImage()); } @@ -496,27 +488,19 @@ void LocationBarViewMac::SetIcon(int resource_id) { } void LocationBarViewMac::SetSecurityLabel() { - std::wstring security_info_text(toolbar_model_->GetSecurityInfoText()); - if (security_info_text.empty()) { - security_label_view_.SetLabel(nil, nil, nil); - security_label_view_.SetVisible(false); - } else { + if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { + std::wstring security_info_text(toolbar_model_->GetEVCertName()); NSString* icon_label = base::SysWideToNSString(security_info_text); - NSColor* color; - if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { - color = [NSColor colorWithCalibratedRed:kEVSecureTextColorRedComponent - green:kEVSecureTextColorGreenComponent - blue:kEVSecureTextColorBlueComponent - alpha:1.0]; - } else { - color = - [NSColor colorWithCalibratedRed:kSecurityErrorTextColorRedComponent - green:kSecurityErrorTextColorGreenComponent - blue:kSecurityErrorTextColorBlueComponent - alpha:1.0]; - } + NSColor* color = + [NSColor colorWithCalibratedRed:kEVSecureTextColorRedComponent + green:kEVSecureTextColorGreenComponent + blue:kEVSecureTextColorBlueComponent + alpha:1.0]; security_label_view_.SetLabel(icon_label, [field_ font], color); security_label_view_.SetVisible(true); + } else { + security_label_view_.SetLabel(nil, nil, nil); + security_label_view_.SetVisible(false); } } diff --git a/chrome/browser/cocoa/location_bar_view_mac_unittest.mm b/chrome/browser/cocoa/location_bar_view_mac_unittest.mm index 733b6619..ecb2a7b 100644 --- a/chrome/browser/cocoa/location_bar_view_mac_unittest.mm +++ b/chrome/browser/cocoa/location_bar_view_mac_unittest.mm @@ -81,7 +81,6 @@ TEST_F(LocationBarViewMacTest, OnChangedImpl) { NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; const std::wstring kKeyword(L"Google"); - const NSString* kSearchHint = @"Type to search"; const NSString* kKeywordPrefix = @"Press "; const NSString* kKeywordSuffix = @" to search Google"; const NSString* kKeywordString = @"Search Google:"; @@ -90,38 +89,19 @@ TEST_F(LocationBarViewMacTest, OnChangedImpl) { [NSString stringWithFormat:@"Search Go%C:", 0x2026]; // With no special hints requested, none set. - LocationBarViewMac::OnChangedImpl( - field_, std::wstring(), std::wstring(), false, false, image); + LocationBarViewMac::OnChangedImpl(field_, std::wstring(), std::wstring(), false, image); EXPECT_FALSE([cell keywordString]); EXPECT_FALSE([cell hintString]); - // Request only a search hint. - LocationBarViewMac::OnChangedImpl( - field_, std::wstring(), std::wstring(), false, true, image); - EXPECT_FALSE([cell keywordString]); - EXPECT_TRUE([[[cell hintString] string] isEqualToString:kSearchHint]); - - // Request a keyword hint, same results whether |search_hint| - // parameter is true or false. - LocationBarViewMac::OnChangedImpl( - field_, kKeyword, kKeyword, true, true, image); - EXPECT_FALSE([cell keywordString]); - EXPECT_TRUE([[[cell hintString] string] hasPrefix:kKeywordPrefix]); - EXPECT_TRUE([[[cell hintString] string] hasSuffix:kKeywordSuffix]); - LocationBarViewMac::OnChangedImpl( - field_, kKeyword, kKeyword, true, false, image); + // Request a keyword hint. + LocationBarViewMac::OnChangedImpl(field_, kKeyword, kKeyword, true, image); EXPECT_FALSE([cell keywordString]); EXPECT_TRUE([[[cell hintString] string] hasPrefix:kKeywordPrefix]); EXPECT_TRUE([[[cell hintString] string] hasSuffix:kKeywordSuffix]); - // Request keyword-search mode, same results whether |search_hint| - // parameter is true or false. - LocationBarViewMac::OnChangedImpl( - field_, kKeyword, kKeyword, false, true, image); - EXPECT_TRUE([[[cell keywordString] string] hasSuffix:kKeywordString]); - EXPECT_FALSE([cell hintString]); + // Request keyword-search mode. LocationBarViewMac::OnChangedImpl( - field_, kKeyword, kKeyword, false, false, image); + field_, kKeyword, kKeyword, false, image); EXPECT_TRUE([[[cell keywordString] string] hasSuffix:kKeywordString]); EXPECT_FALSE([cell hintString]); @@ -132,14 +112,13 @@ TEST_F(LocationBarViewMacTest, OnChangedImpl) { NSRect frame([field_ frame]); frame.size.width = 10.0; [field_ setFrame:frame]; - LocationBarViewMac::OnChangedImpl( - field_, kKeyword, kKeyword, false, true, image); + LocationBarViewMac::OnChangedImpl(field_, kKeyword, kKeyword, false, image); EXPECT_TRUE([[[cell keywordString] string] isEqualToString:kPartialString]); EXPECT_FALSE([cell hintString]); // Transition back to baseline. LocationBarViewMac::OnChangedImpl( - field_, std::wstring(), std::wstring(), false, false, image); + field_, std::wstring(), std::wstring(), false, image); EXPECT_FALSE([cell keywordString]); EXPECT_FALSE([cell hintString]); } diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index eab7c9b..da30537 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -80,7 +80,6 @@ static const int kInnerPadding = 4; // image, but for now we get pretty close by just drawing a solid border. const GdkColor kBorderColor = GDK_COLOR_RGB(0xbe, 0xc8, 0xd4); const GdkColor kEvSecureTextColor = GDK_COLOR_RGB(0x07, 0x95, 0x00); -const GdkColor kSecurityErrorTextColor = GDK_COLOR_RGB(0xa2, 0x00, 0x00); const GdkColor kKeywordBackgroundColor = GDK_COLOR_RGB(0xf0, 0xf4, 0xfa); const GdkColor kKeywordBorderColor = GDK_COLOR_RGB(0xcb, 0xde, 0xf7); @@ -158,7 +157,6 @@ LocationBarViewGtk::LocationBarViewGtk(Browser* browser) tab_to_search_hint_leading_label_(NULL), tab_to_search_hint_icon_(NULL), tab_to_search_hint_trailing_label_(NULL), - type_to_search_hint_(NULL), profile_(NULL), command_updater_(browser->command_updater()), toolbar_model_(browser->toolbar_model()), @@ -170,8 +168,7 @@ LocationBarViewGtk::LocationBarViewGtk(Browser* browser) theme_provider_(NULL), entry_box_width_(0), show_selected_keyword_(false), - show_keyword_hint_(false), - show_search_hint_(false) { + show_keyword_hint_(false) { } LocationBarViewGtk::~LocationBarViewGtk() { @@ -214,10 +211,9 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { BuildLocationIcon(); - // Put |tab_to_search_box_|, |location_entry_|, |tab_to_search_hint_| and - // |type_to_search_hint_| into a sub hbox, so that we can make this part - // horizontally shrinkable without affecting other elements in the location - // bar. + // Put |tab_to_search_box_|, |location_entry_|, and |tab_to_search_hint_| into + // a sub hbox, so that we can make this part horizontally shrinkable without + // affecting other elements in the location bar. GtkWidget* entry_box = gtk_hbox_new(FALSE, kInnerPadding); gtk_widget_show(entry_box); gtk_widget_set_size_request(entry_box, 0, -1); @@ -306,12 +302,6 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { // doesn't work, someone is probably calling show_all on our parent box. gtk_box_pack_end(GTK_BOX(entry_box), tab_to_search_hint_, FALSE, FALSE, 0); - // Type to search hint is on the right hand side. - type_to_search_hint_ = - gtk_label_new(l10n_util::GetStringUTF8(IDS_OMNIBOX_EMPTY_TEXT).c_str()); - gtk_widget_set_sensitive(type_to_search_hint_, FALSE); - gtk_box_pack_end(GTK_BOX(entry_box), type_to_search_hint_, FALSE, FALSE, 0); - // Pack security_info_label_ and security icons in hbox. We hide/show them // by SetSecurityIcon() and SetInfoText(). gtk_box_pack_end(GTK_BOX(hbox_.get()), security_info_label_, FALSE, FALSE, 0); @@ -344,8 +334,6 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { FALSE, FALSE, 0); // Until we switch to vector graphics, force the font size of labels. - gtk_util::ForceFontSizePixels(type_to_search_hint_, - browser_defaults::kAutocompleteEditFontPixelSize); gtk_util::ForceFontSizePixels(security_info_label_, browser_defaults::kAutocompleteEditFontPixelSize); gtk_util::ForceFontSizePixels(tab_to_search_full_label_, @@ -356,8 +344,6 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { browser_defaults::kAutocompleteEditFontPixelSize); gtk_util::ForceFontSizePixels(tab_to_search_hint_trailing_label_, browser_defaults::kAutocompleteEditFontPixelSize); - gtk_util::ForceFontSizePixels(type_to_search_hint_, - browser_defaults::kAutocompleteEditFontPixelSize); registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, @@ -511,8 +497,6 @@ void LocationBarViewGtk::OnChanged() { const bool is_keyword_hint = location_entry_->model()->is_keyword_hint(); show_selected_keyword_ = !keyword.empty() && !is_keyword_hint; show_keyword_hint_ = !keyword.empty() && is_keyword_hint; - show_search_hint_ = location_entry_->model()->show_search_hint(); - DCHECK(keyword.empty() || !show_search_hint_); if (show_selected_keyword_) SetKeywordLabel(keyword); @@ -750,7 +734,6 @@ void LocationBarViewGtk::Observe(NotificationType type, gtk_util::SetLabelColor(tab_to_search_partial_label_, NULL); gtk_util::SetLabelColor(tab_to_search_hint_leading_label_, NULL); gtk_util::SetLabelColor(tab_to_search_hint_trailing_label_, NULL); - gtk_util::SetLabelColor(type_to_search_hint_, NULL); } else { gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, &kKeywordBackgroundColor); @@ -763,7 +746,6 @@ void LocationBarViewGtk::Observe(NotificationType type, &kHintTextColor); gtk_util::SetLabelColor(tab_to_search_hint_trailing_label_, &kHintTextColor); - gtk_util::SetLabelColor(type_to_search_hint_, &kHintTextColor); } UpdateStarIcon(); @@ -826,17 +808,16 @@ void LocationBarViewGtk::UpdateIcon() { } void LocationBarViewGtk::SetInfoText() { - std::wstring info_text = toolbar_model_->GetSecurityInfoText(); - if (info_text.empty()) { - gtk_widget_hide(GTK_WIDGET(security_info_label_)); - } else { + if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { + std::wstring info_text = toolbar_model_->GetEVCertName(); gtk_widget_modify_fg(GTK_WIDGET(security_info_label_), GTK_STATE_NORMAL, - toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE ? - &kEvSecureTextColor : &kSecurityErrorTextColor); + &kEvSecureTextColor); + gtk_label_set_text(GTK_LABEL(security_info_label_), + WideToUTF8(info_text).c_str()); gtk_widget_show(GTK_WIDGET(security_info_label_)); + } else { + gtk_widget_hide(GTK_WIDGET(security_info_label_)); } - gtk_label_set_text(GTK_LABEL(security_info_label_), - WideToUTF8(info_text).c_str()); } void LocationBarViewGtk::SetKeywordLabel(const std::wstring& keyword) { @@ -1006,20 +987,15 @@ void LocationBarViewGtk::AdjustChildrenVisibility() { int text_width = location_entry_->TextWidth(); int available_width = entry_box_width_ - text_width - kInnerPadding; - // Only one of |tab_to_search_box_|, |tab_to_search_hint_| and - // |type_to_search_hint_| can be visible at the same time. + // Only one of |tab_to_search_box_| and |tab_to_search_hint_| can be visible + // at the same time. if (!show_selected_keyword_ && GTK_WIDGET_VISIBLE(tab_to_search_box_)) { gtk_widget_hide(tab_to_search_box_); } else if (!show_keyword_hint_ && GTK_WIDGET_VISIBLE(tab_to_search_hint_)) { gtk_widget_hide(tab_to_search_hint_); location_entry_->set_enable_tab_to_search(false); - } else if (!show_search_hint_ && GTK_WIDGET_VISIBLE(type_to_search_hint_)) { - gtk_widget_hide(type_to_search_hint_); } - if (!show_selected_keyword_ && !show_keyword_hint_ && !show_search_hint_) - return; - if (show_selected_keyword_) { GtkRequisition box, full_label, partial_label; gtk_widget_size_request(tab_to_search_box_, &box); @@ -1068,13 +1044,6 @@ void LocationBarViewGtk::AdjustChildrenVisibility() { gtk_widget_show(tab_to_search_hint_); location_entry_->set_enable_tab_to_search(true); } - } else if (show_search_hint_) { - GtkRequisition requisition; - gtk_widget_size_request(type_to_search_hint_, &requisition); - if (requisition.width >= available_width) - gtk_widget_hide(type_to_search_hint_); - else if (requisition.width < available_width) - gtk_widget_show(type_to_search_hint_); } } diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h index fb8bb38..faea404 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.h +++ b/chrome/browser/gtk/location_bar_view_gtk.h @@ -297,10 +297,9 @@ class LocationBarViewGtk : public AutocompleteEditController, void ShowFirstRunBubbleInternal(FirstRun::BubbleType bubble_type); - // Show or hide |tab_to_search_box_|, |tab_to_search_hint_| and - // |type_to_search_hint_| according to the value of |show_selected_keyword_|, - // |show_keyword_hint_|, |show_search_hint_| and the available horizontal - // space in the location bar. + // Show or hide |tab_to_search_box_| and |tab_to_search_hint_| according to + // the value of |show_selected_keyword_|, |show_keyword_hint_|, and the + // available horizontal space in the location bar. void AdjustChildrenVisibility(); // Build the star icon. @@ -355,9 +354,6 @@ class LocationBarViewGtk : public AutocompleteEditController, GtkWidget* tab_to_search_hint_icon_; GtkWidget* tab_to_search_hint_trailing_label_; - // Hint to user that the inputted text is not a keyword or url. - GtkWidget* type_to_search_hint_; - scoped_ptr<AutocompleteEditViewGtk> location_entry_; Profile* profile_; @@ -398,9 +394,6 @@ class LocationBarViewGtk : public AutocompleteEditController, // Indicate if |tab_to_search_hint_| should be shown. bool show_keyword_hint_; - // Indicate if |type_to_search_hint_| should be shown. - bool show_search_hint_; - DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtk); }; diff --git a/chrome/browser/toolbar_model.cc b/chrome/browser/toolbar_model.cc index 9e79335..c641539 100644 --- a/chrome/browser/toolbar_model.cc +++ b/chrome/browser/toolbar_model.cc @@ -100,7 +100,7 @@ ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const { int ToolbarModel::GetIcon() const { static int icon_ids[NUM_SECURITY_LEVELS] = { IDR_OMNIBOX_HTTP, - IDR_OMNIBOX_HTTPS_GREEN, + IDR_OMNIBOX_HTTPS_VALID, IDR_OMNIBOX_HTTPS_VALID, IDR_OMNIBOX_HTTPS_WARNING, IDR_OMNIBOX_HTTPS_INVALID, @@ -109,30 +109,14 @@ int ToolbarModel::GetIcon() const { return icon_ids[GetSecurityLevel()]; } -std::wstring ToolbarModel::GetSecurityInfoText() const { - switch (GetSecurityLevel()) { - case NONE: - case SECURE: - case SECURITY_WARNING: - return std::wstring(); - - case EV_SECURE: { - scoped_refptr<net::X509Certificate> cert; - // Note: Navigation controller and active entry are guaranteed non-NULL - // or the security level would be NONE. - CertStore::GetSharedInstance()->RetrieveCert( - GetNavigationController()->GetActiveEntry()->ssl().cert_id(), - &cert); - return SSLManager::GetEVCertName(*cert); - } - - case SECURITY_ERROR: - return l10n_util::GetString(IDS_SECURITY_BROKEN); - - default: - NOTREACHED(); - return std::wstring(); - } +std::wstring ToolbarModel::GetEVCertName() const { + DCHECK_EQ(GetSecurityLevel(), EV_SECURE); + scoped_refptr<net::X509Certificate> cert; + // Note: Navigation controller and active entry are guaranteed non-NULL or + // the security level would be NONE. + CertStore::GetSharedInstance()->RetrieveCert( + GetNavigationController()->GetActiveEntry()->ssl().cert_id(), &cert); + return SSLManager::GetEVCertName(*cert); } NavigationController* ToolbarModel::GetNavigationController() const { diff --git a/chrome/browser/toolbar_model.h b/chrome/browser/toolbar_model.h index 96a48e5..a4959e6fd 100644 --- a/chrome/browser/toolbar_model.h +++ b/chrome/browser/toolbar_model.h @@ -45,9 +45,9 @@ class ToolbarModel { // user is editing; see AutocompleteEditView::GetIcon(). int GetIcon() const; - // Returns the text, if any, that should be displayed on the right of the - // location bar. - std::wstring GetSecurityInfoText() const; + // Returns the name of the EV cert holder. Only call this when the security + // level is EV_SECURE. + std::wstring GetEVCertName() const; // Getter/setter of whether the text in location bar is currently being // edited. diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc index 8a571c9..de0464e 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc @@ -90,11 +90,8 @@ const int kIconVerticalPadding = 2; // bottom of the row. See comment about the use of "minimum" for // kIconVerticalPadding. const int kTextVerticalPadding = 3; -// The padding at the edges of the row. -const int kRowPadding = 3; -// The horizontal distance between the right edge of the icon and the left edge -// of the text. -const int kIconTextSpacing = 4; +// The padding between horizontally adjacent items (including row edges). +const int kHorizontalPadding = 3; // The size delta between the font used for the edit and the result rows. Passed // to gfx::Font::DeriveFont. #if !defined(OS_CHROMEOS) @@ -320,7 +317,8 @@ void AutocompleteResultView::Paint(gfx::Canvas* canvas) { // position of an input text. bool text_mirroring = View::UILayoutIsRightToLeft(); int text_left = MirroredLeftPointForRect(text_bounds_); - int text_right = text_mirroring ? x - kIconTextSpacing : text_bounds_.right(); + int text_right = + text_mirroring ? (x - kHorizontalPadding) : text_bounds_.right(); x = mirroring_context_->Initialize(text_left, text_right, text_mirroring); x = DrawString(canvas, match_.contents, match_.contents_class, false, x, text_bounds_.y()); @@ -341,12 +339,12 @@ void AutocompleteResultView::Paint(gfx::Canvas* canvas) { } void AutocompleteResultView::Layout() { - icon_bounds_.SetRect(kRowPadding, (height() - icon_size_) / 2, icon_size_, - icon_size_); - int text_x = icon_bounds_.right() + kIconTextSpacing; + icon_bounds_.SetRect(kHorizontalPadding, (height() - icon_size_) / 2, + icon_size_, icon_size_); + int text_x = icon_bounds_.right() + kHorizontalPadding; text_bounds_.SetRect(text_x, std::max(0, (height() - font_.height()) / 2), - std::max(0, bounds().right() - text_x - kRowPadding), - font_.height()); + std::max(0, bounds().right() - text_x - kHorizontalPadding), + font_.height()); } gfx::Size AutocompleteResultView::GetPreferredSize() { @@ -471,8 +469,8 @@ int AutocompleteResultView::DrawStringFragment( gfx::Font display_font = GetFragmentFont(style); // Clamp text width to the available width within the popup so we elide if // necessary. - int string_width = - std::min(display_font.GetStringWidth(text), width() - kRowPadding - x); + int string_width = std::min(display_font.GetStringWidth(text), + width() - kHorizontalPadding - x); int string_left = mirroring_context_->GetLeft(x, x + string_width); const int flags = force_rtl_directionality ? gfx::Canvas::FORCE_RTL_DIRECTIONALITY : 0; diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index d6ca539..a4e6da7 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -44,11 +44,26 @@ using views::View; // static const int LocationBarView::kVertMargin = 2; -// Padding on the right and left of the entry field. -static const int kEntryPadding = 3; +// Padding between items in the location bar. +static const int kViewPadding = 3; -// Padding between the entry and the leading/trailing views. -static const int kInnerPadding = 3; +// Padding before the start of a bubble. +static const int kBubblePadding = kViewPadding - 1; + +// Padding between the location icon and the edit, if they're adjacent. +static const int kLocationIconEditPadding = kViewPadding - 1; + +static const int kEVBubbleBackgroundImages[] = { + IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_L, + IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_C, + IDR_OMNIBOX_EV_BUBBLE_BACKGROUND_R, +}; + +static const int kSelectedKeywordBackgroundImages[] = { + IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_L, + IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_C, + IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_R, +}; static const SkBitmap* kBackground = NULL; @@ -131,14 +146,17 @@ LocationBarView::LocationBarView(Profile* profile, model_(model), delegate_(delegate), disposition_(CURRENT_TAB), - location_icon_view_(this), + ALLOW_THIS_IN_INITIALIZER_LIST(location_icon_view_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(ev_bubble_view_( + kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, + GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this)), location_entry_view_(NULL), - selected_keyword_view_(profile), + selected_keyword_view_(kSelectedKeywordBackgroundImages, + IDR_OMNIBOX_SEARCH, SK_ColorBLACK, profile), keyword_hint_view_(profile), - type_to_search_view_(l10n_util::GetString(IDS_OMNIBOX_EMPTY_TEXT)), star_view_(command_updater), popup_window_mode_(popup_window_mode), - first_run_bubble_(this) { + ALLOW_THIS_IN_INITIALIZER_LIST(first_run_bubble_(this)) { DCHECK(profile_); SetID(VIEW_ID_LOCATION_BAR); SetFocusable(true); @@ -167,6 +185,11 @@ void LocationBarView::Init() { location_icon_view_.SetDragController(this); location_icon_view_.set_parent_owned(false); + AddChildView(&ev_bubble_view_); + ev_bubble_view_.SetVisible(false); + ev_bubble_view_.SetDragController(this); + ev_bubble_view_.set_parent_owned(false); + // URL edit field. // View container for URL edit field. #if defined(OS_WIN) @@ -197,22 +220,12 @@ void LocationBarView::Init() { SkColor dimmed_text = GetColor(ToolbarModel::NONE, DEEMPHASIZED_TEXT); - AddChildView(&type_to_search_view_); - type_to_search_view_.SetVisible(false); - type_to_search_view_.SetFont(font_); - type_to_search_view_.SetColor(dimmed_text); - type_to_search_view_.set_parent_owned(false); - AddChildView(&keyword_hint_view_); keyword_hint_view_.SetVisible(false); keyword_hint_view_.SetFont(font_); keyword_hint_view_.SetColor(dimmed_text); keyword_hint_view_.set_parent_owned(false); - AddChildView(&security_info_label_); - security_info_label_.SetVisible(false); - security_info_label_.set_parent_owned(false); - for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { ContentSettingImageView* content_blocked_view = new ContentSettingImageView( static_cast<ContentSettingsType>(i), this, profile_); @@ -265,12 +278,12 @@ SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, SkColor color; switch (security_level) { case ToolbarModel::EV_SECURE: + case ToolbarModel::SECURE: color = SkColorSetRGB(7, 149, 0); break; - case ToolbarModel::SECURE: case ToolbarModel::SECURITY_WARNING: - color = SkColorSetRGB(0, 14, 149); + return GetColor(security_level, DEEMPHASIZED_TEXT); break; case ToolbarModel::SECURITY_ERROR: @@ -292,14 +305,6 @@ SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, } void LocationBarView::Update(const TabContents* tab_for_state_restoring) { - // The visibility of the |security_info_label_| will be set during layout. - std::wstring security_info_text(model_->GetSecurityInfoText()); - security_info_label_.SetText(security_info_text); - if (!security_info_text.empty()) { - security_info_label_.SetColor(GetColor(model_->GetSecurityLevel(), - SECURITY_TEXT)); - } - RefreshContentSettingViews(); RefreshPageActionViews(); location_entry_->Update(tab_for_state_restoring); @@ -417,32 +422,41 @@ void LocationBarView::Layout() { if (!location_entry_.get()) return; - int entry_width = width() - (kEntryPadding * 2); + int entry_width = width() - kViewPadding; - // |location_icon_view_| is always visible except when - // |selected_keyword_view_| is visible. + // |location_icon_view_| is visible except when |ev_bubble_view_| or + // |selected_keyword_view_| are visible. int location_icon_width = 0; + int ev_bubble_width = 0; + location_icon_view_.SetVisible(false); + ev_bubble_view_.SetVisible(false); const std::wstring keyword(location_entry_->model()->keyword()); const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; if (show_selected_keyword) { - location_icon_view_.SetVisible(false); + entry_width -= kViewPadding; // Assume the keyword might be hidden. + } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { + ev_bubble_view_.SetVisible(true); + ev_bubble_view_.SetLabel(model_->GetEVCertName()); + ev_bubble_width = ev_bubble_view_.GetPreferredSize().width(); + entry_width -= kBubblePadding + ev_bubble_width + kViewPadding; } else { location_icon_view_.SetVisible(true); location_icon_width = location_icon_view_.GetPreferredSize().width(); - entry_width -= location_icon_width + kInnerPadding; + entry_width -= + kViewPadding + location_icon_width + kLocationIconEditPadding; } - entry_width -= star_view_.GetPreferredSize().width() + kInnerPadding; + entry_width -= star_view_.GetPreferredSize().width() + kViewPadding; for (PageActionViews::const_iterator i(page_action_views_.begin()); i != page_action_views_.end(); ++i) { if ((*i)->IsVisible()) - entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding; + entry_width -= (*i)->GetPreferredSize().width() + kViewPadding; } for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); i != content_setting_views_.end(); ++i) { if ((*i)->IsVisible()) - entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding; + entry_width -= (*i)->GetPreferredSize().width() + kViewPadding; } #if defined(OS_WIN) @@ -461,26 +475,8 @@ void LocationBarView::Layout() { const int available_width = AvailableWidth(max_edit_width); const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; - bool show_search_hint(location_entry_->model()->show_search_hint()); - DCHECK(keyword.empty() || !show_search_hint); - - if (show_search_hint) { - // Only show type to search if all the text fits. - gfx::Size preferred_size = type_to_search_view_.GetPreferredSize(); - show_search_hint = UsePref(preferred_size.width(), available_width); - } - - bool show_security_info_label = !security_info_label_.GetText().empty(); - if (show_security_info_label) { - // Only show the security info label if all the text fits. - gfx::Size preferred_size = security_info_label_.GetPreferredSize(); - show_security_info_label = UsePref(preferred_size.width(), available_width); - } - selected_keyword_view_.SetVisible(show_selected_keyword); keyword_hint_view_.SetVisible(show_keyword_hint); - type_to_search_view_.SetVisible(show_search_hint); - security_info_label_.SetVisible(show_security_info_label); if (show_selected_keyword) { if (selected_keyword_view_.keyword() != keyword) selected_keyword_view_.SetKeyword(keyword); @@ -494,11 +490,11 @@ void LocationBarView::Layout() { int location_height = std::max(height() - location_y - kVertMargin, 0); // Lay out items to the right of the edit field. - int offset = width() - kEntryPadding; + int offset = width() - kViewPadding; int star_width = star_view_.GetPreferredSize().width(); offset -= star_width; star_view_.SetBounds(offset, location_y, star_width, location_height); - offset -= kInnerPadding; + offset -= kViewPadding; for (PageActionViews::const_iterator i(page_action_views_.begin()); i != page_action_views_.end(); ++i) { @@ -506,7 +502,7 @@ void LocationBarView::Layout() { int page_action_width = (*i)->GetPreferredSize().width(); offset -= page_action_width; (*i)->SetBounds(offset, location_y, page_action_width, location_height); - offset -= kInnerPadding; + offset -= kViewPadding; } } // We use a reverse_iterator here because we're laying out the views from @@ -519,16 +515,21 @@ void LocationBarView::Layout() { offset -= content_blocked_width; (*i)->SetBounds(offset, location_y, content_blocked_width, location_height); - offset -= kInnerPadding; + offset -= kViewPadding; } } // Now lay out items to the left of the edit field. - offset = kEntryPadding; if (location_icon_view_.IsVisible()) { - location_icon_view_.SetBounds(offset, location_y, location_icon_width, + location_icon_view_.SetBounds(kViewPadding, location_y, location_icon_width, location_height); - offset = location_icon_view_.bounds().right() + kInnerPadding; + offset = location_icon_view_.bounds().right() + kLocationIconEditPadding; + } else if (ev_bubble_view_.IsVisible()) { + ev_bubble_view_.SetBounds(kBubblePadding, location_y, ev_bubble_width, + location_height); + offset = ev_bubble_view_.bounds().right() + kViewPadding; + } else { + offset = show_selected_keyword ? kBubblePadding : kViewPadding; } // Now lay out the edit field and views that autocollapse to give it more @@ -537,16 +538,13 @@ void LocationBarView::Layout() { if (show_selected_keyword) { LayoutView(true, &selected_keyword_view_, available_width, &location_bounds); + if (!selected_keyword_view_.IsVisible()) { + location_bounds.set_x( + location_bounds.x() + kViewPadding - kBubblePadding); + } } else if (show_keyword_hint) { LayoutView(false, &keyword_hint_view_, available_width, &location_bounds); - } else if (show_search_hint) { - LayoutView(false, &type_to_search_view_, available_width, - &location_bounds); - } - if (show_security_info_label) { - LayoutView(false, &security_info_label_, available_width, - &location_bounds); } location_entry_view_->SetBounds(location_bounds); @@ -704,7 +702,7 @@ int LocationBarView::AvailableWidth(int location_bar_width) { } bool LocationBarView::UsePref(int pref_width, int available_width) { - return (pref_width + kInnerPadding <= available_width); + return (pref_width + kViewPadding <= available_width); } void LocationBarView::LayoutView(bool leading, @@ -715,19 +713,19 @@ void LocationBarView::LayoutView(bool leading, gfx::Size view_size = view->GetPreferredSize(); if (!UsePref(view_size.width(), available_width)) view_size = view->GetMinimumSize(); - if (view_size.width() + kInnerPadding >= bounds->width()) { + if (view_size.width() + kViewPadding >= bounds->width()) { view->SetVisible(false); return; } if (leading) { view->SetBounds(bounds->x(), bounds->y(), view_size.width(), bounds->height()); - bounds->Offset(view_size.width() + kInnerPadding, 0); + bounds->Offset(view_size.width() + kViewPadding, 0); } else { view->SetBounds(bounds->right() - view_size.width(), bounds->y(), view_size.width(), bounds->height()); } - bounds->set_width(bounds->width() - view_size.width() - kInnerPadding); + bounds->set_width(bounds->width() - view_size.width() - kViewPadding); view->SetVisible(true); } @@ -891,7 +889,7 @@ void LocationBarView::WriteDragData(views::View* sender, int LocationBarView::GetDragOperations(views::View* sender, const gfx::Point& p) { - DCHECK(sender == &location_icon_view_); + DCHECK((sender == &location_icon_view_) || (sender == &ev_bubble_view_)); TabContents* tab_contents = delegate_->GetTabContents(); return (tab_contents && tab_contents->GetURL().is_valid() && !location_entry()->IsEditingOrEmpty()) ? @@ -905,11 +903,39 @@ bool LocationBarView::CanStartDrag(View* sender, return true; } -// LocationIconView------------------------------------------------------------- +// ClickHandler ---------------------------------------------------------------- + +LocationBarView::ClickHandler::ClickHandler(const views::View* owner, + const LocationBarView* location_bar) + : owner_(owner), + location_bar_(location_bar) { +} + +void LocationBarView::ClickHandler::OnMouseReleased( + const views::MouseEvent& event, + bool canceled) { + if (canceled || !owner_->HitTest(event.location())) + return; + + // Do not show page info if the user has been editing the location + // bar, or the location bar is at the NTP. + if (location_bar_->location_entry()->IsEditingOrEmpty()) + return; + + TabContents* tab = location_bar_->GetTabContents(); + NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); + if (!nav_entry) { + NOTREACHED(); + return; + } + tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); +} + +// LocationIconView ------------------------------------------------------------ LocationBarView::LocationIconView::LocationIconView( - const LocationBarView* parent) - : parent_(parent) { + const LocationBarView* location_bar) + : ALLOW_THIS_IN_INITIALIZER_LIST(click_handler_(this, location_bar)) { } LocationBarView::LocationIconView::~LocationIconView() { @@ -925,115 +951,136 @@ bool LocationBarView::LocationIconView::OnMousePressed( void LocationBarView::LocationIconView::OnMouseReleased( const views::MouseEvent& event, bool canceled) { - if (canceled || !HitTest(event.location())) - return; + click_handler_.OnMouseReleased(event, canceled); +} - // Do not show page info if the user has been editing the location - // bar, or the location bar is at the NTP. - if (parent_->location_entry()->IsEditingOrEmpty()) - return; +// IconLabelBubbleView --------------------------------------------------------- - TabContents* tab = parent_->GetTabContents(); - NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); - if (!nav_entry) { - NOTREACHED(); - return; - } - tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); +// Amount to offset the image. +static const int kImageOffset = 1; + +// Amount to offset the label from the image. +static const int kLabelOffset = 3; + +// Amount of padding after the label. +static const int kLabelPadding = 4; + +LocationBarView::IconLabelBubbleView::IconLabelBubbleView( + const int background_images[], + int contained_image, + const SkColor& color) + : background_painter_(background_images) { + AddChildView(&image_); + image_.set_parent_owned(false); + image_.SetImage( + ResourceBundle::GetSharedInstance().GetBitmapNamed(contained_image)); + AddChildView(&label_); + label_.set_parent_owned(false); + label_.SetColor(color); } -// SelectedKeywordView ------------------------------------------------------- +LocationBarView::IconLabelBubbleView::~IconLabelBubbleView() { +} -// The background is drawn using HorizontalPainter. This is the -// left/center/right image names. -static const int kBorderImages[] = { - IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_L, - IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_C, - IDR_LOCATION_BAR_SELECTED_KEYWORD_BACKGROUND_R }; +void LocationBarView::IconLabelBubbleView::SetFont(const gfx::Font& font) { + label_.SetFont(font); +} -// Insets around the label. -static const int kTopInset = 0; -static const int kBottomInset = 0; -static const int kLeftInset = 4; -static const int kRightInset = 4; +void LocationBarView::IconLabelBubbleView::SetLabel(const std::wstring& label) { + label_.SetText(label); +} -// Amount to offset the search image. This is relative to kLeftInset -// (or kRightInset if rtl). -static const int kSearchOffset = 2; +void LocationBarView::IconLabelBubbleView::Paint(gfx::Canvas* canvas) { + int y_offset = (GetParent()->height() - height()) / 2; + canvas->TranslateInt(0, y_offset); + background_painter_.Paint(width(), height(), canvas); + canvas->TranslateInt(0, -y_offset); +} -// Offset from the top the background is drawn at. -static const int kBackgroundYOffset = 2; +gfx::Size LocationBarView::IconLabelBubbleView::GetPreferredSize() { + gfx::Size size(GetNonLabelSize()); + size.Enlarge(label_.GetPreferredSize().width(), 0); + return size; +} -LocationBarView::SelectedKeywordView::SelectedKeywordView(Profile* profile) - : background_painter_(kBorderImages), +void LocationBarView::IconLabelBubbleView::Layout() { + image_.SetBounds(kImageOffset, 0, image_.GetPreferredSize().width(), + height()); + gfx::Size label_size(label_.GetPreferredSize()); + label_.SetBounds(image_.x() + image_.width() + kLabelOffset, + (height() - label_size.height()) / 2, label_size.width(), + label_size.height()); +} + +gfx::Size LocationBarView::IconLabelBubbleView::GetNonLabelSize() { + return gfx::Size(kImageOffset + image_.GetPreferredSize().width() + + kLabelOffset + kLabelPadding, background_painter_.height()); +} + +// EVBubbleView ---------------------------------------------------------------- + +LocationBarView::EVBubbleView::EVBubbleView(const int background_images[], + int contained_image, + const SkColor& color, + const LocationBarView* location_bar) + : IconLabelBubbleView(background_images, contained_image, color), + ALLOW_THIS_IN_INITIALIZER_LIST(click_handler_(this, location_bar)) { +} + +LocationBarView::EVBubbleView::~EVBubbleView() { +} + +bool LocationBarView::EVBubbleView::OnMousePressed( + const views::MouseEvent& event) { + // We want to show the dialog on mouse release; that is the standard behavior + // for buttons. + return true; +} + +void LocationBarView::EVBubbleView::OnMouseReleased( + const views::MouseEvent& event, + bool canceled) { + click_handler_.OnMouseReleased(event, canceled); +} + +// SelectedKeywordView --------------------------------------------------------- + +LocationBarView::SelectedKeywordView::SelectedKeywordView( + const int background_images[], + int contained_image, + const SkColor& color, + Profile* profile) + : IconLabelBubbleView(background_images, contained_image, color), profile_(profile) { - AddChildView(&full_label_); - AddChildView(&partial_label_); - // Full_label and partial_label are deleted by us, make sure View doesn't - // delete them too. - full_label_.set_parent_owned(false); - partial_label_.set_parent_owned(false); full_label_.SetVisible(false); partial_label_.SetVisible(false); - SkBitmap* search_icon = - ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_OMNIBOX_SEARCH); - int left_inset = kLeftInset + - (UILayoutIsRightToLeft() ? 0 : search_icon->width() - kSearchOffset); - int right_inset = kRightInset + - (UILayoutIsRightToLeft() ? search_icon->width() - kSearchOffset: 0); - full_label_.set_border( - views::Border::CreateEmptyBorder(kTopInset, left_inset, kBottomInset, - right_inset)); - partial_label_.set_border( - views::Border::CreateEmptyBorder(kTopInset, left_inset, kBottomInset, - right_inset)); - full_label_.SetColor(SK_ColorBLACK); - partial_label_.SetColor(SK_ColorBLACK); } LocationBarView::SelectedKeywordView::~SelectedKeywordView() { } void LocationBarView::SelectedKeywordView::SetFont(const gfx::Font& font) { + IconLabelBubbleView::SetFont(font); full_label_.SetFont(font); partial_label_.SetFont(font); } -void LocationBarView::SelectedKeywordView::Paint(gfx::Canvas* canvas) { - canvas->TranslateInt(0, kBackgroundYOffset); - - background_painter_.Paint(width(), height() - kTopInset, canvas); - - // Draw the search image. - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - SkBitmap* search_icon = rb.GetBitmapNamed(IDR_OMNIBOX_SEARCH); - int image_x = UILayoutIsRightToLeft() ? - (width() - search_icon->width() - kRightInset + kSearchOffset) : - kLeftInset - kSearchOffset; - int image_y = (rb.GetBitmapNamed(kBorderImages[0])->height() - - search_icon->height()) / 2; - canvas->DrawBitmapInt(*search_icon, image_x, image_y); - - canvas->TranslateInt(0, -kBackgroundYOffset); -} - gfx::Size LocationBarView::SelectedKeywordView::GetPreferredSize() { - return full_label_.GetPreferredSize(); + gfx::Size size(GetNonLabelSize()); + size.Enlarge(full_label_.GetPreferredSize().width(), 0); + return size; } gfx::Size LocationBarView::SelectedKeywordView::GetMinimumSize() { - return partial_label_.GetMinimumSize(); + gfx::Size size(GetNonLabelSize()); + size.Enlarge(partial_label_.GetMinimumSize().width(), 0); + return size; } void LocationBarView::SelectedKeywordView::Layout() { - gfx::Size pref = GetPreferredSize(); - bool at_pref = (width() == pref.width()); - if (at_pref) - full_label_.SetBounds(0, 0, width(), height()); - else - partial_label_.SetBounds(0, 0, width(), height()); - full_label_.SetVisible(at_pref); - partial_label_.SetVisible(!at_pref); + SetLabel((width() == GetPreferredSize().width()) ? + full_label_.GetText() : partial_label_.GetText()); + IconLabelBubbleView::Layout(); } void LocationBarView::SelectedKeywordView::SetKeyword( @@ -1049,12 +1096,9 @@ void LocationBarView::SelectedKeywordView::SetKeyword( full_label_.SetText(l10n_util::GetStringF(IDS_OMNIBOX_KEYWORD_TEXT, short_name)); const std::wstring min_string = CalculateMinString(short_name); - if (!min_string.empty()) { - partial_label_.SetText( - l10n_util::GetStringF(IDS_OMNIBOX_KEYWORD_TEXT, min_string)); - } else { - partial_label_.SetText(full_label_.GetText()); - } + partial_label_.SetText(min_string.empty() ? + full_label_.GetText() : + l10n_util::GetStringF(IDS_OMNIBOX_KEYWORD_TEXT, min_string)); } std::wstring LocationBarView::SelectedKeywordView::CalculateMinString( diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h index 331028b..956523b 100644 --- a/chrome/browser/views/location_bar_view.h +++ b/chrome/browser/views/location_bar_view.h @@ -205,12 +205,28 @@ class LocationBarView : public LocationBar, void Focus(); private: + // This helper class is kept as a member by classes that need to show the Page + // Info dialog on click, to encapsulate that logic in one place. + class ClickHandler { + public: + explicit ClickHandler(const views::View* owner, + const LocationBarView* location_bar); + + void OnMouseReleased(const views::MouseEvent& event, bool canceled); + + private: + const views::View* owner_; + const LocationBarView* location_bar_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(ClickHandler); + }; + // LocationIconView is used to display an icon to the left of the edit field. // This shows the user's current action while editing, the page security // status on https pages, or a globe for other URLs. class LocationIconView : public views::ImageView { public: - explicit LocationIconView(const LocationBarView* parent); + explicit LocationIconView(const LocationBarView* location_bar); virtual ~LocationIconView(); // Overridden from view. @@ -218,26 +234,71 @@ class LocationBarView : public LocationBar, virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); private: - // The owning LocationBarView. - const LocationBarView* parent_; + ClickHandler click_handler_; - DISALLOW_COPY_AND_ASSIGN(LocationIconView); + DISALLOW_IMPLICIT_CONSTRUCTORS(LocationIconView); }; - // View used when the user has selected a keyword. - // - // SelectedKeywordView maintains two labels. One label contains the - // complete description of the keyword, the second contains a truncated - // version of the description. The second is used if there is not enough room - // to display the complete description. - class SelectedKeywordView : public views::View { + // View used to draw a bubble to the left of the address, containing an icon + // and a label. We use this as a base for the classes that handle the EV + // bubble and tab-to-search UI. + class IconLabelBubbleView : public views::View { public: - explicit SelectedKeywordView(Profile* profile); - virtual ~SelectedKeywordView(); + IconLabelBubbleView(const int background_images[], + int contained_image, + const SkColor& color); + virtual ~IconLabelBubbleView(); void SetFont(const gfx::Font& font); + void SetLabel(const std::wstring& label); virtual void Paint(gfx::Canvas* canvas); + virtual gfx::Size GetPreferredSize(); + virtual void Layout(); + + protected: + gfx::Size GetNonLabelSize(); + + private: + // For painting the background. + views::HorizontalPainter background_painter_; + + // The contents of the bubble. + views::ImageView image_; + views::Label label_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(IconLabelBubbleView); + }; + + // EVBubbleView displays the EV Bubble. + class EVBubbleView : public IconLabelBubbleView { + public: + EVBubbleView(const int background_images[], + int contained_image, + const SkColor& color, + const LocationBarView* location_bar); + virtual ~EVBubbleView(); + + // Overridden from view. + virtual bool OnMousePressed(const views::MouseEvent& event); + virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); + + private: + ClickHandler click_handler_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(EVBubbleView); + }; + + // SelectedKeywordView displays the tab-to-search UI. + class SelectedKeywordView : public IconLabelBubbleView { + public: + SelectedKeywordView(const int background_images[], + int contained_image, + const SkColor& color, + Profile* profile); + virtual ~SelectedKeywordView(); + + void SetFont(const gfx::Font& font); virtual gfx::Size GetPreferredSize(); virtual gfx::Size GetMinimumSize(); @@ -258,18 +319,16 @@ class LocationBarView : public LocationBar, // deleted out from under us. std::wstring keyword_; - // For painting the background. - views::HorizontalPainter background_painter_; - - // Label containing the complete description. + // These labels are never visible. They are used to size the view. One + // label contains the complete description of the keyword, the second + // contains a truncated version of the description, for if there is not + // enough room to display the complete description. views::Label full_label_; - - // Label containing the partial description. views::Label partial_label_; Profile* profile_; - DISALLOW_COPY_AND_ASSIGN(SelectedKeywordView); + DISALLOW_IMPLICIT_CONSTRUCTORS(SelectedKeywordView); }; // KeywordHintView is used to display a hint to the user when the selected @@ -309,7 +368,7 @@ class LocationBarView : public LocationBar, Profile* profile_; - DISALLOW_COPY_AND_ASSIGN(KeywordHintView); + DISALLOW_IMPLICIT_CONSTRUCTORS(KeywordHintView); }; class ContentSettingImageView : public views::ImageView, @@ -433,7 +492,7 @@ class LocationBarView : public LocationBar, // The current popup and the button it came from. NULL if no popup. ExtensionPopup* popup_; - DISALLOW_COPY_AND_ASSIGN(PageActionImageView); + DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView); }; friend class PageActionImageView; @@ -546,15 +605,17 @@ class LocationBarView : public LocationBar, // An icon to the left of the edit field. LocationIconView location_icon_view_; + // A bubble displayed for EV HTTPS sites. + EVBubbleView ev_bubble_view_; + // Location_entry view wrapper views::NativeViewHost* location_entry_view_; // The following views are used to provide hints and remind the user as to // what is going in the edit. They are all added a children of the // LocationBarView. At most one is visible at a time. Preference is - // given to the keyword_view_, then hint_view_, then type_to_search_view_. - // These, as well as |security_info_label_|, autocollapse when the edit needs - // the room. + // given to the keyword_view_, then hint_view_. + // These autocollapse when the edit needs the room. // Shown if the user has selected a keyword. SelectedKeywordView selected_keyword_view_; @@ -562,13 +623,6 @@ class LocationBarView : public LocationBar, // Shown if the selected url has a corresponding keyword. KeywordHintView keyword_hint_view_; - // Shown if the text is not a keyword or url. - views::Label type_to_search_view_; - - // A label displayed on the right side of the box to show more information - // about certain security states. - views::Label security_info_label_; - // The content setting views. ContentSettingViews content_setting_views_; @@ -588,7 +642,7 @@ class LocationBarView : public LocationBar, // Storage of string needed for accessibility. std::wstring accessible_name_; - DISALLOW_COPY_AND_ASSIGN(LocationBarView); + DISALLOW_IMPLICIT_CONSTRUCTORS(LocationBarView); }; #endif // CHROME_BROWSER_VIEWS_LOCATION_BAR_VIEW_H_ |