diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-23 20:01:00 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-23 20:01:00 +0000 |
commit | 69c579e522c4493c15c93ebf33b28a35b1e7213b (patch) | |
tree | 5dde3cc78e0de04bb87613c09be12b47b80d8307 /chrome/browser/views/location_bar_view.cc | |
parent | 12f144239468f206dc82c3f3481fef477f636798 (diff) | |
download | chromium_src-69c579e522c4493c15c93ebf33b28a35b1e7213b.zip chromium_src-69c579e522c4493c15c93ebf33b28a35b1e7213b.tar.gz chromium_src-69c579e522c4493c15c93ebf33b28a35b1e7213b.tar.bz2 |
Re-instate the temporary revert from r45267. That reverted certain
Omnibox, toolbar, tab animations, and other UI changes for purposes of
testing and merging into mstone-5.
Additionally reverts these CLs to fix the earlier revert:
r45271: [Mac] Image references missing from Omnibox revert.
r45268: GTK fix merge failure in uber-revert.
Additional revert which fixed a bug for the branch:
r45381: [Mac] Omnibox popup icons and text lined up under toolbar.
Slight merge conflict which should be good:
r45322: GTK: Implement OnDragCanceled() for autocomplete...
Also ++kThemePackVersion and regenerate the cached theme pak.
Re-instated changes:
r45213: GTK: Override cursor colors in chrome-theme mode.
r45103: Support drawing nano tabs in the tabstrip.
r45084: GTK: Position the EV certificate stuff inside a green bubble.
r44979: Subclassing the InfoBubble to handle anchoring bubbles basedon...
r44957: GTK: Tint the geolocation icons in gtk mode.
r44943: Changes FormatURL to not strip http if the host starts with ft...
r44930: Remove an icon that is no longer used.
r44929: SSL UI changes, Windows, code side (images are separate).
r44859: SSL UI changes (icons). TBRed since trybots hate binary patches.
r44822: GTK: Select better greens in the native omnibox popup.
r44814: GTK: navigate to URL on PRIMARY when middle-clicking the locat...
r44789: [Mac] Bookmark star missing on NTP and BMM.
r44775: [Mac] Centralize hack to make tests work with AutocompleteClas...
r44678: Display the SECURITY_WARNING status in the location bar for the
r44648: [Mac] Add an arrow cursor rect for the location image.
r44615: Revert r44611 because it may have broken "unit_tests" on "Vist...
r44611: Display the SECURITY_WARNING status in the location bar for the
r44577: Revert 44572 - [Mac] Update locationbar icon as user types.
r44572: [Mac] Update location-bar icon as user types.
r44555: GTK: Use correct button mask on reload button.
r44545: [Mac] Omnibox text drag drag URL when select-all.
r44523: GTK: Prevent inappropriate drag of location bar location icon.
r44519: GTK: make the primary selection include the url's scheme when ...
r44492: [Mac] Fix search icon in keyword search to be right-side-up.
r44415: GTK: Update top padding on icons in the autocomplete popup.
r44401: GTK: Tint omnibox icons in GTK mode differently.
r44380: GTK: Move reload in gtk mode and fix omnibox popup location.
r44282: Fixes crash in autocomplete when typing some URLs. The problem
r44273: [Mac] PDF icons for omnibox nits.
r44269: Fix build break due to bad merge resolve
r44268: Shift omnibox dropdown in and up on Windows, and square off th...
r44178: GTK: fix TTS padding.
r44177: Round the top left and right edges of the toolbar.
r44171: Images only checkin for try server goodness.
r44163: GTK: fix padding of autocomplete popup.
r44152: [Mac] PDF icons for omnibox.
r44145: GTK: Theme the icons in the location bar and use GTK colors fo...
r44140: Strips http from the omnibox
r44131: Fixes bugs in new tab strip animations where they weren't doin...
r44116: Change the default theme colors.
r44117: Add newline to EOF to fix CrOS builder.
r44115: Make the bottom edges of the opaque frame rounded.
r44091: [Mac] No star icon or page actions in omnibox on popups.
r44087: Don't allow drag or click on location icon when editing in omn...
r44021: [GTK] Add TTS lens graphic to linux TTS box.
r44008: [Mac] Tweak location icon spacing in omnibox.
r43977: GTK: don't show the star or page actions in ShouldOnlyShowLoca...
r43972: Make the firstrun bubble point at a better spot now that the l...
r43971: [Mac] Location icon in omnibox as drag source.
r43970: Make the star and page action icons not appear on popup windows.
r43954: Fixes bug in TabStrip where dragging tab out then back in rapidly
r43864: Tweaks to BoundsAnimator/SlideAnimation and TabStrip:
r43787: Allow location icon to be dragged & dropped. This also fixes ...
r43759: Changes end cap of tab-to-search images.
r43740: Change bookmark bar toggle to ctrl-shift-b.
r43723: Show Page Info dialog on mouse up, not mouse down.
r43677: Fix Mac build failure.
r43676: Replace omnibox icons with new set that are all the same size ...
r43596: Fix browser test TestStarButtonAccObj.
r43593: Disables TestStarButtonAccObj.
r43582: Changes tab strip to use BoundsAnimator for tab strip animatio...
r43563: GTK: don't show reload button for popup/app windows.
r43562: Star/reload shuffle, Windows version.
r43540: [Mac] Magnifying glass in keyword-search bubble.
r43482: Adds images needed for new tab animation. I'm separating this ...
r43422: Add reload mask resource.
r43392: GTK: make the location icon a drag source.
r43376: [Mac] Move star button into page-actions area of omnibox.
r43357: [Mac] Line up omnibox popup under field.
r43290: gtk: fix display of icons in omnibox popup
r43269: GTK: fix reload button.
r43249: [Mac] Rearrange SSL status icon/label in omnibox.
r43248: BrowserThemePack: Adds persistant ids for the reload endcaps.
r43241: GTK: more location bar updates.
r43191: Fix memory leak in BrowserThemePack.
r43154: GTK: set the new star button's ID
r43151: Fix bad conflict resolution for r43146.
r43146: GTK: toolbar reload/star shuffle.
r43025: Show the location bar icon (almost) all the time, and have its...
r43023: Add new images for new reload button. No code change.
r42782: Remove this icon, now that it's no longer used (due to my secu...
r42502: Omnibox M5 work, part 1: Security changes
r42245: Check in new icons for omnibox security changes alone, so that...
BUG=none
TEST=People go back to complaining about missing http://.
R=pkasting@chromium.org,beng@chromium.org
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45474 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/location_bar_view.cc')
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 1254 |
1 files changed, 597 insertions, 657 deletions
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index 7a1e4d9..935598c 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -8,6 +8,7 @@ #include <gtk/gtk.h> #endif +#include "app/drag_drop_types.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/theme_provider.h" @@ -16,8 +17,6 @@ #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/alternate_nav_url_fetcher.h" #include "chrome/browser/browser_list.h" -#include "chrome/browser/browser_window.h" -#include "chrome/browser/bubble_positioner.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/content_setting_bubble_model.h" #include "chrome/browser/content_setting_image_model.h" @@ -26,17 +25,15 @@ #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/view_ids.h" -#include "chrome/browser/views/extensions/extension_popup.h" -#include "chrome/browser/views/frame/browser_view.h" +#include "chrome/browser/views/browser_dialogs.h" #include "chrome/browser/views/content_blocked_bubble_contents.h" -#include "chrome/common/content_settings.h" +#include "chrome/browser/views/frame/browser_view.h" #include "chrome/common/platform_util.h" -#include "chrome/common/pref_names.h" #include "gfx/canvas.h" #include "gfx/color_utils.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" -#include "net/base/net_util.h" +#include "views/drag_utils.h" #if defined(OS_WIN) #include "chrome/browser/views/first_run_bubble.h" @@ -47,20 +44,31 @@ 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 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; -// Padding between the entry and the leading/trailing views. -static const int kInnerPadding = 3; +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; static const SkBitmap* kPopupBackground = NULL; -// The delay the mouse has to be hovering over the lock/warning icon before the -// info bubble is shown. -static const int kInfoBubbleHoverDelayMs = 500; - // The tab key image. static const SkBitmap* kTabButtonBitmap = NULL; @@ -132,21 +140,23 @@ LocationBarView::LocationBarView(Profile* profile, CommandUpdater* command_updater, ToolbarModel* model, Delegate* delegate, - bool popup_window_mode, - const BubblePositioner* bubble_positioner) + bool popup_window_mode) : profile_(profile), command_updater_(command_updater), model_(model), delegate_(delegate), disposition_(CURRENT_TAB), + 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)), - security_image_view_(this, profile, model, bubble_positioner), + star_view_(command_updater), popup_window_mode_(popup_window_mode), - first_run_bubble_(this), - bubble_positioner_(bubble_positioner) { + ALLOW_THIS_IN_INITIALIZER_LIST(first_run_bubble_(this)) { DCHECK(profile_); SetID(VIEW_ID_LOCATION_BAR); SetFocusable(true); @@ -170,52 +180,45 @@ void LocationBarView::Init() { font_ = font_.DeriveFont(3); } + AddChildView(&location_icon_view_); + location_icon_view_.SetVisible(true); + 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) - views::Widget* widget = GetWidget(); location_entry_.reset(new AutocompleteEditViewWin(font_, this, model_, this, - widget->GetNativeView(), - profile_, command_updater_, - popup_window_mode_, - bubble_positioner_)); + GetWidget()->GetNativeView(), profile_, command_updater_, + popup_window_mode_, this)); #else location_entry_.reset(new AutocompleteEditViewGtk(this, model_, profile_, - command_updater_, - popup_window_mode_, - bubble_positioner_)); + command_updater_, popup_window_mode_, this)); location_entry_->Init(); // Make all the children of the widget visible. NOTE: this won't display // anything, it just toggles the visible flag. - gtk_widget_show_all(location_entry_->widget()); + gtk_widget_show_all(location_entry_->GetNativeView()); // Hide the widget. NativeViewHostGtk will make it visible again as // necessary. - gtk_widget_hide(location_entry_->widget()); + gtk_widget_hide(location_entry_->GetNativeView()); #endif location_entry_view_ = new views::NativeViewHost; location_entry_view_->SetID(VIEW_ID_AUTOCOMPLETE); AddChildView(location_entry_view_); location_entry_view_->set_focus_view(this); - location_entry_view_->Attach( -#if defined(OS_WIN) - location_entry_->m_hWnd -#else - location_entry_->widget() -#endif - ); // NOLINT + location_entry_view_->Attach(location_entry_->GetNativeView()); AddChildView(&selected_keyword_view_); selected_keyword_view_.SetFont(font_); selected_keyword_view_.SetVisible(false); selected_keyword_view_.set_parent_owned(false); - SkColor dimmed_text = GetColor(false, 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); + SkColor dimmed_text = GetColor(ToolbarModel::NONE, DEEMPHASIZED_TEXT); AddChildView(&keyword_hint_view_); keyword_hint_view_.SetVisible(false); @@ -223,22 +226,19 @@ void LocationBarView::Init() { keyword_hint_view_.SetColor(dimmed_text); keyword_hint_view_.set_parent_owned(false); - AddChildView(&security_image_view_); - security_image_view_.SetVisible(false); - security_image_view_.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_, bubble_positioner_); + ContentSettingImageView* content_blocked_view = new ContentSettingImageView( + static_cast<ContentSettingsType>(i), this, profile_); content_setting_views_.push_back(content_blocked_view); AddChildView(content_blocked_view); content_blocked_view->SetVisible(false); } - AddChildView(&info_label_); - info_label_.SetVisible(false); - info_label_.set_parent_owned(false); + if (!popup_window_mode_) { + AddChildView(&star_view_); + star_view_.SetVisible(true); + star_view_.set_parent_owned(false); + } // Notify us when any ancestor is resized. In this case we want to tell the // AutocompleteEditView to close its popup. @@ -256,63 +256,59 @@ bool LocationBarView::IsInitialized() const { } // static -SkColor LocationBarView::GetColor(bool is_secure, ColorKind kind) { - enum SecurityState { - NOT_SECURE = 0, - SECURE, - NUM_STATES - }; - - static bool initialized = false; - static SkColor colors[NUM_STATES][NUM_KINDS]; - if (!initialized) { +SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, + ColorKind kind) { + switch (kind) { #if defined(OS_WIN) - colors[NOT_SECURE][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW); - colors[NOT_SECURE][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); - colors[NOT_SECURE][SELECTED_TEXT] = - color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); + case BACKGROUND: return color_utils::GetSysSkColor(COLOR_WINDOW); + case TEXT: return color_utils::GetSysSkColor(COLOR_WINDOWTEXT); + case SELECTED_TEXT: return color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); #else // TODO(beng): source from theme provider. - colors[NOT_SECURE][BACKGROUND] = SK_ColorWHITE; - colors[NOT_SECURE][TEXT] = SK_ColorBLACK; - colors[NOT_SECURE][SELECTED_TEXT] = SK_ColorWHITE; + case BACKGROUND: return SK_ColorWHITE; + case TEXT: return SK_ColorBLACK; + case SELECTED_TEXT: return SK_ColorWHITE; #endif - colors[SECURE][BACKGROUND] = SkColorSetRGB(255, 245, 195); - colors[SECURE][TEXT] = SK_ColorBLACK; - colors[SECURE][SELECTED_TEXT] = 0; // Unused - colors[NOT_SECURE][DEEMPHASIZED_TEXT] = - color_utils::AlphaBlend(colors[NOT_SECURE][TEXT], - colors[NOT_SECURE][BACKGROUND], 128); - colors[SECURE][DEEMPHASIZED_TEXT] = - color_utils::AlphaBlend(colors[SECURE][TEXT], - colors[SECURE][BACKGROUND], 128); - colors[NOT_SECURE][SECURITY_TEXT] = color_utils::GetReadableColor( - SkColorSetRGB(200, 0, 0), colors[NOT_SECURE][BACKGROUND]); - colors[SECURE][SECURITY_TEXT] = SkColorSetRGB(0, 150, 20); - colors[NOT_SECURE][SECURITY_INFO_BUBBLE_TEXT] = - colors[NOT_SECURE][SECURITY_TEXT]; - colors[SECURE][SECURITY_INFO_BUBBLE_TEXT] = color_utils::GetReadableColor( - SkColorSetRGB(0, 153, 51), colors[NOT_SECURE][BACKGROUND]); - colors[NOT_SECURE][SCHEME_STRIKEOUT] = color_utils::GetReadableColor( - SkColorSetRGB(210, 0, 0), colors[NOT_SECURE][BACKGROUND]); - colors[SECURE][SCHEME_STRIKEOUT] = 0; // Unused - initialized = true; - } - return colors[is_secure ? SECURE : NOT_SECURE][kind]; + case DEEMPHASIZED_TEXT: + return color_utils::AlphaBlend(GetColor(security_level, TEXT), + GetColor(security_level, BACKGROUND), 128); + + case SECURITY_TEXT: { + SkColor color; + switch (security_level) { + case ToolbarModel::EV_SECURE: + case ToolbarModel::SECURE: + color = SkColorSetRGB(7, 149, 0); + break; + + case ToolbarModel::SECURITY_WARNING: + return GetColor(security_level, DEEMPHASIZED_TEXT); + break; + + case ToolbarModel::SECURITY_ERROR: + color = SkColorSetRGB(162, 0, 0); + break; + + default: + NOTREACHED(); + return GetColor(security_level, TEXT); + } + return color_utils::GetReadableColor(color, GetColor(security_level, + BACKGROUND)); + } + + default: + NOTREACHED(); + return GetColor(security_level, TEXT); + } } void LocationBarView::Update(const TabContents* tab_for_state_restoring) { - SetSecurityIcon(model_->GetIcon()); RefreshContentSettingViews(); RefreshPageActionViews(); - std::wstring info_text, info_tooltip; - ToolbarModel::InfoTextType info_text_type = - model_->GetInfoText(&info_text, &info_tooltip); - SetInfoText(info_text, info_text_type, info_tooltip); location_entry_->Update(tab_for_state_restoring); - Layout(); - SchedulePaint(); + OnChanged(); } void LocationBarView::UpdateContentSettingsIcons() { @@ -362,7 +358,6 @@ void LocationBarView::SetProfile(Profile* profile) { for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); i != content_setting_views_.end(); ++i) (*i)->set_profile(profile); - security_image_view_.set_profile(profile); } } @@ -370,8 +365,11 @@ TabContents* LocationBarView::GetTabContents() const { return delegate_->GetTabContents(); } -void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction *page_action, +void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action, bool preview_enabled) { + if (popup_window_mode_) + return; + DCHECK(page_action); TabContents* contents = delegate_->GetTabContents(); @@ -400,13 +398,156 @@ views::View* LocationBarView::GetPageActionView( return NULL; } +void LocationBarView::SetStarToggled(bool on) { + star_view_.SetToggled(on); +} + +void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { + gfx::Rect screen_bounds(star_view_.GetImageBounds()); + // Compensate for some built-in padding in the Star image. + screen_bounds.Inset(1, 1, 1, 2); + gfx::Point origin(screen_bounds.origin()); + views::View::ConvertPointToScreen(&star_view_, &origin); + screen_bounds.set_origin(origin); + browser::ShowBookmarkBubbleView(GetWindow(), screen_bounds, &star_view_, + profile_, url, newly_bookmarked); +} + gfx::Size LocationBarView::GetPreferredSize() { return gfx::Size(0, (popup_window_mode_ ? kPopupBackground : kBackground)->height()); } void LocationBarView::Layout() { - DoLayout(true); + if (!location_entry_.get()) + return; + + int entry_width = width() - kViewPadding; + + // |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) { + 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 -= + kViewPadding + location_icon_width + kLocationIconEditPadding; + } + + 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() + kViewPadding; + } + for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); + i != content_setting_views_.end(); ++i) { + if ((*i)->IsVisible()) + entry_width -= (*i)->GetPreferredSize().width() + kViewPadding; + } + +#if defined(OS_WIN) + RECT formatting_rect; + location_entry_->GetRect(&formatting_rect); + RECT edit_bounds; + location_entry_->GetClientRect(&edit_bounds); + int max_edit_width = entry_width - formatting_rect.left - + (edit_bounds.right - formatting_rect.right); +#else + int max_edit_width = entry_width; +#endif + + if (max_edit_width < 0) + return; + const int available_width = AvailableWidth(max_edit_width); + + const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; + selected_keyword_view_.SetVisible(show_selected_keyword); + keyword_hint_view_.SetVisible(show_keyword_hint); + if (show_selected_keyword) { + if (selected_keyword_view_.keyword() != keyword) + selected_keyword_view_.SetKeyword(keyword); + } else if (show_keyword_hint) { + if (keyword_hint_view_.keyword() != keyword) + keyword_hint_view_.SetKeyword(keyword); + } + + // TODO(sky): baseline layout. + int location_y = TopMargin(); + int location_height = std::max(height() - location_y - kVertMargin, 0); + + // Lay out items to the right of the edit field. + 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 -= kViewPadding; + + for (PageActionViews::const_iterator i(page_action_views_.begin()); + i != page_action_views_.end(); ++i) { + if ((*i)->IsVisible()) { + int page_action_width = (*i)->GetPreferredSize().width(); + offset -= page_action_width; + (*i)->SetBounds(offset, location_y, page_action_width, location_height); + offset -= kViewPadding; + } + } + // We use a reverse_iterator here because we're laying out the views from + // right to left but in the vector they're ordered left to right. + for (ContentSettingViews::const_reverse_iterator + i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); + ++i) { + if ((*i)->IsVisible()) { + int content_blocked_width = (*i)->GetPreferredSize().width(); + offset -= content_blocked_width; + (*i)->SetBounds(offset, location_y, content_blocked_width, + location_height); + offset -= kViewPadding; + } + } + + // Now lay out items to the left of the edit field. + if (location_icon_view_.IsVisible()) { + location_icon_view_.SetBounds(kViewPadding, location_y, location_icon_width, + location_height); + 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 + // room. + gfx::Rect location_bounds(offset, location_y, entry_width, location_height); + 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); + } + + location_entry_view_->SetBounds(location_bounds); } void LocationBarView::Paint(gfx::Canvas* canvas) { @@ -419,10 +560,9 @@ void LocationBarView::Paint(gfx::Canvas* canvas) { canvas->TileImageInt(*background, 0, 0, 0, 0, width(), height()); int top_margin = TopMargin(); - canvas->FillRectInt( - GetColor(model_->GetSchemeSecurityLevel() == ToolbarModel::SECURE, - BACKGROUND), - 0, top_margin, width(), std::max(height() - top_margin - kVertMargin, 0)); + canvas->FillRectInt(GetColor(ToolbarModel::NONE, BACKGROUND), 0, + top_margin, width(), + std::max(height() - top_margin - kVertMargin, 0)); } void LocationBarView::VisibleBoundsInRootChanged() { @@ -509,7 +649,11 @@ void LocationBarView::OnAutocompleteAccept( } void LocationBarView::OnChanged() { - DoLayout(false); + location_icon_view_.SetImage( + ResourceBundle::GetSharedInstance().GetBitmapNamed( + location_entry_->GetIcon())); + Layout(); + SchedulePaint(); } void LocationBarView::OnInputInProgress(bool in_progress) { @@ -540,117 +684,6 @@ std::wstring LocationBarView::GetTitle() const { return UTF16ToWideHack(delegate_->GetTabContents()->GetTitle()); } -void LocationBarView::DoLayout(const bool force_layout) { - if (!location_entry_.get()) - return; - - int entry_width = width() - (kEntryPadding * 2); - - for (PageActionViews::const_iterator i(page_action_views_.begin()); - i != page_action_views_.end(); ++i) { - if ((*i)->IsVisible()) - entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding; - } - for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); - i != content_setting_views_.end(); ++i) { - if ((*i)->IsVisible()) - entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding; - } - gfx::Size security_image_size; - if (security_image_view_.IsVisible()) { - security_image_size = security_image_view_.GetPreferredSize(); - entry_width -= security_image_size.width() + kInnerPadding; - } - gfx::Size info_label_size; - if (info_label_.IsVisible()) { - info_label_size = info_label_.GetPreferredSize(); - entry_width -= (info_label_size.width() + kInnerPadding); - } - -#if defined(OS_WIN) - RECT formatting_rect; - location_entry_->GetRect(&formatting_rect); - RECT edit_bounds; - location_entry_->GetClientRect(&edit_bounds); - int max_edit_width = entry_width - formatting_rect.left - - (edit_bounds.right - formatting_rect.right); -#else - int max_edit_width = entry_width; -#endif - - if (max_edit_width < 0) - return; - const int available_width = AvailableWidth(max_edit_width); - bool needs_layout = force_layout; - needs_layout |= AdjustHints(available_width); - - if (!needs_layout) - return; - - // TODO(sky): baseline layout. - int location_y = TopMargin(); - int location_height = std::max(height() - location_y - kVertMargin, 0); - - // First set the bounds for the label that appears to the right of the - // security icon. - int offset = width() - kEntryPadding; - if (info_label_.IsVisible()) { - offset -= info_label_size.width(); - info_label_.SetBounds(offset, location_y, - info_label_size.width(), location_height); - offset -= kInnerPadding; - } - if (security_image_view_.IsVisible()) { - offset -= security_image_size.width(); - security_image_view_.SetBounds(offset, location_y, - security_image_size.width(), - location_height); - offset -= kInnerPadding; - } - - for (PageActionViews::const_iterator i(page_action_views_.begin()); - i != page_action_views_.end(); ++i) { - if ((*i)->IsVisible()) { - int page_action_width = (*i)->GetPreferredSize().width(); - offset -= page_action_width; - (*i)->SetBounds(offset, location_y, page_action_width, location_height); - offset -= kInnerPadding; - } - } - // We use a reverse_iterator here because we're laying out the views from - // right to left but in the vector they're ordered left to right. - for (ContentSettingViews::const_reverse_iterator - i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); - ++i) { - if ((*i)->IsVisible()) { - int content_blocked_width = (*i)->GetPreferredSize().width(); - offset -= content_blocked_width; - (*i)->SetBounds(offset, location_y, content_blocked_width, - location_height); - offset -= kInnerPadding; - } - } - gfx::Rect location_bounds(kEntryPadding, location_y, entry_width, - location_height); - if (selected_keyword_view_.IsVisible()) { - LayoutView(true, &selected_keyword_view_, available_width, - &location_bounds); - } else if (keyword_hint_view_.IsVisible()) { - LayoutView(false, &keyword_hint_view_, available_width, - &location_bounds); - } else if (type_to_search_view_.IsVisible()) { - LayoutView(false, &type_to_search_view_, available_width, - &location_bounds); - } - - location_entry_view_->SetBounds(location_bounds); - if (!force_layout) { - // If force_layout is false and we got this far it means one of the views - // was added/removed or changed in size. We need to paint ourselves. - SchedulePaint(); - } -} - int LocationBarView::TopMargin() const { return std::min(kVertMargin, height()); } @@ -669,52 +702,7 @@ int LocationBarView::AvailableWidth(int location_bar_width) { } bool LocationBarView::UsePref(int pref_width, int available_width) { - return (pref_width + kInnerPadding <= available_width); -} - -bool LocationBarView::NeedsResize(View* view, int available_width) { - gfx::Size size = view->GetPreferredSize(); - if (!UsePref(size.width(), available_width)) - size = view->GetMinimumSize(); - return (view->width() != size.width()); -} - -bool LocationBarView::AdjustHints(int available_width) { - 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; - 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 view_pref = type_to_search_view_.GetPreferredSize(); - show_search_hint = UsePref(view_pref.width(), available_width); - } - - // NOTE: This isn't just one big || statement as ToggleVisibility MUST be - // invoked for each view. - bool needs_layout = false; - needs_layout |= ToggleVisibility(show_selected_keyword, - &selected_keyword_view_); - needs_layout |= ToggleVisibility(show_keyword_hint, &keyword_hint_view_); - needs_layout |= ToggleVisibility(show_search_hint, &type_to_search_view_); - if (show_selected_keyword) { - if (selected_keyword_view_.keyword() != keyword) { - needs_layout = true; - selected_keyword_view_.SetKeyword(keyword); - } - needs_layout |= NeedsResize(&selected_keyword_view_, available_width); - } else if (show_keyword_hint) { - if (keyword_hint_view_.keyword() != keyword) { - needs_layout = true; - keyword_hint_view_.SetKeyword(keyword); - } - needs_layout |= NeedsResize(&keyword_hint_view_, available_width); - } - - return needs_layout; + return (pref_width + kViewPadding <= available_width); } void LocationBarView::LayoutView(bool leading, @@ -725,40 +713,20 @@ 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()) { - view->SetVisible(true); - if (leading) { - view->SetBounds(bounds->x(), bounds->y(), view_size.width(), - bounds->height()); - bounds->Offset(view_size.width() + kInnerPadding, 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); - } else { + if (view_size.width() + kViewPadding >= bounds->width()) { view->SetVisible(false); + return; } -} - -void LocationBarView::SetSecurityIcon(ToolbarModel::Icon icon) { - switch (icon) { - case ToolbarModel::LOCK_ICON: - security_image_view_.SetImageShown(SecurityImageView::LOCK); - security_image_view_.SetVisible(true); - break; - case ToolbarModel::WARNING_ICON: - security_image_view_.SetImageShown(SecurityImageView::WARNING); - security_image_view_.SetVisible(true); - break; - case ToolbarModel::NO_ICON: - security_image_view_.SetVisible(false); - break; - default: - NOTREACHED(); - security_image_view_.SetVisible(false); - break; + if (leading) { + view->SetBounds(bounds->x(), bounds->y(), view_size.width(), + bounds->height()); + 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() - kViewPadding); + view->SetVisible(true); } void LocationBarView::RefreshContentSettingViews() { @@ -778,7 +746,9 @@ void LocationBarView::DeletePageActionViews() { } void LocationBarView::RefreshPageActionViews() { - std::vector<ExtensionAction*> page_actions; + if (popup_window_mode_) + return; + ExtensionsService* service = profile_->GetExtensionsService(); if (!service) return; @@ -790,6 +760,7 @@ void LocationBarView::RefreshPageActionViews() { // Remember the previous visibility of the page actions so that we can // notify when this changes. + std::vector<ExtensionAction*> page_actions; for (size_t i = 0; i < service->extensions()->size(); ++i) { if (service->extensions()->at(i)->page_action()) page_actions.push_back(service->extensions()->at(i)->page_action()); @@ -804,8 +775,7 @@ void LocationBarView::RefreshPageActionViews() { for (size_t i = 0; i < page_actions.size(); ++i) { page_action_views_[i] = new PageActionWithBadgeView( - new PageActionImageView(this, profile_, - page_actions[i], bubble_positioner_)); + new PageActionImageView(this, profile_, page_actions[i])); page_action_views_[i]->SetVisible(false); AddChildView(page_action_views_[i]); } @@ -832,25 +802,6 @@ void LocationBarView::RefreshPageActionViews() { } } -void LocationBarView::SetInfoText(const std::wstring& text, - ToolbarModel::InfoTextType text_type, - const std::wstring& tooltip_text) { - info_label_.SetVisible(!text.empty()); - info_label_.SetText(text); - if (text_type == ToolbarModel::INFO_EV_TEXT) - info_label_.SetColor(GetColor(true, SECURITY_TEXT)); - info_label_.SetTooltipText(tooltip_text); -} - -bool LocationBarView::ToggleVisibility(bool new_vis, View* view) { - DCHECK(view); - if (view->IsVisible() != new_vis) { - view->SetVisible(new_vis); - return true; - } - return false; -} - #if defined(OS_WIN) void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { UINT flags = 0; @@ -867,11 +818,55 @@ void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { gfx::Point screen_point(event.location()); ConvertPointToScreen(this, &screen_point); - location_entry_->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); } #endif +void LocationBarView::ShowFirstRunBubbleInternal( + FirstRun::BubbleType bubble_type) { +#if defined(OS_WIN) // First run bubble doesn't make sense for Chrome OS. + // If the browser is no longer active, let's not show the info bubble, as this + // would make the browser the active window again. + if (!location_entry_view_ || !location_entry_view_->GetWidget()->IsActive()) + return; + + // Point at the start of the edit control; adjust to look as good as possible. + const int kXOffset = 1; // Text looks like it actually starts 1 px in. + const int kYOffset = -4; // Point into the omnibox, not just at its edge. + gfx::Point origin(location_entry_view_->bounds().x() + kXOffset, + y() + height() + kYOffset); + // If the UI layout is RTL, the coordinate system is not transformed and + // therefore we need to adjust the X coordinate so that bubble appears on the + // right hand side of the location bar. + if (UILayoutIsRightToLeft()) + origin.set_x(width() - origin.x()); + views::View::ConvertPointToScreen(this, &origin); + FirstRunBubble::Show(profile_, GetWindow(), gfx::Rect(origin, gfx::Size()), + bubble_type); +#endif +} + +bool LocationBarView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { + if (keyword_hint_view_.IsVisible() && + views::FocusManager::IsTabTraversalKeyEvent(e)) { + // We want to receive tab key events when the hint is showing. + return true; + } + +#if defined(OS_WIN) + return location_entry_->SkipDefaultKeyEventProcessing(e); +#else + // TODO(jcampan): We need to refactor the code of + // AutocompleteEditViewWin::SkipDefaultKeyEventProcessing into this class so + // it can be shared between Windows and Linux. + // For now, we just override back-space as it is the accelerator for back + // navigation. + if (e.GetKeyCode() == base::VKEY_BACK) + return true; + return false; +#endif +} + bool LocationBarView::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); @@ -879,76 +874,213 @@ bool LocationBarView::GetAccessibleRole(AccessibilityTypes::Role* role) { return true; } -// SelectedKeywordView ------------------------------------------------------- -// 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::WriteDragData(views::View* sender, + const gfx::Point& press_pt, + OSExchangeData* data) { + DCHECK(GetDragOperations(sender, press_pt) != DragDropTypes::DRAG_NONE); + + TabContents* tab_contents = delegate_->GetTabContents(); + DCHECK(tab_contents); + drag_utils::SetURLAndDragImage(tab_contents->GetURL(), + UTF16ToWideHack(tab_contents->GetTitle()), + tab_contents->GetFavIcon(), data); +} + +int LocationBarView::GetDragOperations(views::View* sender, + const gfx::Point& p) { + 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()) ? + (DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK) : + DragDropTypes::DRAG_NONE; +} + +bool LocationBarView::CanStartDrag(View* sender, + const gfx::Point& press_pt, + const gfx::Point& p) { + return true; +} + +// 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* location_bar) + : ALLOW_THIS_IN_INITIALIZER_LIST(click_handler_(this, location_bar)) { +} + +LocationBarView::LocationIconView::~LocationIconView() { +} + +bool LocationBarView::LocationIconView::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::LocationIconView::OnMouseReleased( + const views::MouseEvent& event, + bool canceled) { + click_handler_.OnMouseReleased(event, canceled); +} + +// IconLabelBubbleView --------------------------------------------------------- + +// 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); +} + +LocationBarView::IconLabelBubbleView::~IconLabelBubbleView() { +} + +void LocationBarView::IconLabelBubbleView::SetFont(const gfx::Font& font) { + label_.SetFont(font); +} + +void LocationBarView::IconLabelBubbleView::SetLabel(const std::wstring& label) { + label_.SetText(label); +} + +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); +} + +gfx::Size LocationBarView::IconLabelBubbleView::GetPreferredSize() { + gfx::Size size(GetNonLabelSize()); + size.Enlarge(label_.GetPreferredSize().width(), 0); + return size; +} + +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; +} -// 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::EVBubbleView::OnMouseReleased( + const views::MouseEvent& event, + bool canceled) { + click_handler_.OnMouseReleased(event, canceled); +} -// Offset from the top the background is drawn at. -static const int kBackgroundYOffset = 2; +// SelectedKeywordView --------------------------------------------------------- -LocationBarView::SelectedKeywordView::SelectedKeywordView(Profile* profile) - : background_painter_(kBorderImages), +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); - full_label_.set_border( - views::Border::CreateEmptyBorder(kTopInset, kLeftInset, kBottomInset, - kRightInset)); - partial_label_.set_border( - views::Border::CreateEmptyBorder(kTopInset, kLeftInset, kBottomInset, - kRightInset)); - 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); - 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( @@ -964,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( @@ -1096,250 +1225,18 @@ void LocationBarView::KeywordHintView::Layout() { } } -bool LocationBarView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { - if (keyword_hint_view_.IsVisible() && - views::FocusManager::IsTabTraversalKeyEvent(e)) { - // We want to receive tab key events when the hint is showing. - return true; - } - -#if defined(OS_WIN) - return location_entry_->SkipDefaultKeyEventProcessing(e); -#else - // TODO(jcampan): We need to refactor the code of - // AutocompleteEditViewWin::SkipDefaultKeyEventProcessing into this class so - // it can be shared between Windows and Linux. - // For now, we just override back-space as it is the accelerator for back - // navigation. - if (e.GetKeyCode() == base::VKEY_BACK) - return true; - return false; -#endif -} - -// ShowInfoBubbleTask----------------------------------------------------------- - -class LocationBarView::ShowInfoBubbleTask : public Task { - public: - explicit ShowInfoBubbleTask( - LocationBarView::LocationBarImageView* image_view); - virtual void Run(); - void Cancel(); - - private: - LocationBarView::LocationBarImageView* image_view_; - bool cancelled_; - - DISALLOW_COPY_AND_ASSIGN(ShowInfoBubbleTask); -}; - -LocationBarView::ShowInfoBubbleTask::ShowInfoBubbleTask( - LocationBarView::LocationBarImageView* image_view) - : image_view_(image_view), - cancelled_(false) { -} - -void LocationBarView::ShowInfoBubbleTask::Run() { - if (cancelled_) - return; - - if (!image_view_->GetWidget()->IsActive()) { - // The browser is no longer active. Let's not show the info bubble, this - // would make the browser the active window again. Also makes sure we NULL - // show_info_bubble_task_ to prevent the SecurityImageView from keeping a - // dangling pointer. - image_view_->show_info_bubble_task_ = NULL; - return; - } - - image_view_->ShowInfoBubble(); -} - -void LocationBarView::ShowInfoBubbleTask::Cancel() { - cancelled_ = true; -} - -// ----------------------------------------------------------------------------- - -void LocationBarView::ShowFirstRunBubbleInternal( - FirstRun::BubbleType bubble_type) { - if (!location_entry_view_) - return; - if (!location_entry_view_->GetWidget()->IsActive()) { - // The browser is no longer active. Let's not show the info bubble, this - // would make the browser the active window again. - return; - } - - gfx::Point location; - - // If the UI layout is RTL, the coordinate system is not transformed and - // therefore we need to adjust the X coordinate so that bubble appears on the - // right hand side of the location bar. - if (UILayoutIsRightToLeft()) - location.Offset(width(), 0); - views::View::ConvertPointToScreen(this, &location); - - // We try to guess that 20 pixels offset is a good place for the first - // letter in the OmniBox. - gfx::Rect bounds(location.x(), location.y(), 20, height()); - - // Moving the bounds "backwards" so that it appears within the location bar - // if the UI layout is RTL. - if (UILayoutIsRightToLeft()) - bounds.set_x(location.x() - 20); - -#if defined(OS_WIN) - FirstRunBubble::Show(profile_, GetWindow(), bounds, bubble_type); -#else - // First run bubble doesn't make sense for Chrome OS. -#endif -} - -// LocationBarImageView--------------------------------------------------------- - -LocationBarView::LocationBarImageView::LocationBarImageView( - const BubblePositioner* bubble_positioner) - : info_bubble_(NULL), - show_info_bubble_task_(NULL), - bubble_positioner_(bubble_positioner) { -} - -LocationBarView::LocationBarImageView::~LocationBarImageView() { - if (show_info_bubble_task_) - show_info_bubble_task_->Cancel(); - - if (info_bubble_) - info_bubble_->Close(); -} - -void LocationBarView::LocationBarImageView::OnMouseMoved( - const views::MouseEvent& event) { - if (show_info_bubble_task_) { - show_info_bubble_task_->Cancel(); - show_info_bubble_task_ = NULL; - } - - if (info_bubble_) { - // If an info bubble is currently showing, nothing to do. - return; - } - - show_info_bubble_task_ = new ShowInfoBubbleTask(this); - MessageLoop::current()->PostDelayedTask(FROM_HERE, show_info_bubble_task_, - kInfoBubbleHoverDelayMs); -} - -void LocationBarView::LocationBarImageView::OnMouseExited( - const views::MouseEvent& event) { - if (show_info_bubble_task_) { - show_info_bubble_task_->Cancel(); - show_info_bubble_task_ = NULL; - } - - if (info_bubble_) - info_bubble_->Close(); -} - -void LocationBarView::LocationBarImageView::InfoBubbleClosing( - InfoBubble* info_bubble, bool closed_by_escape) { - info_bubble_ = NULL; -} - -void LocationBarView::LocationBarImageView::ShowInfoBubbleImpl( - const std::wstring& text, SkColor text_color) { - gfx::Rect bounds(bubble_positioner_->GetLocationStackBounds()); - gfx::Point location; - views::View::ConvertPointToScreen(this, &location); - bounds.set_x(location.x()); - bounds.set_width(width()); - - views::Label* label = new views::Label(text); - label->SetMultiLine(true); - label->SetColor(text_color); - label->SetFont(ResourceBundle::GetSharedInstance().GetFont( - ResourceBundle::BaseFont).DeriveFont(2)); - label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - label->SizeToFit(0); - DCHECK(info_bubble_ == NULL); - info_bubble_ = InfoBubble::Show(GetWindow(), bounds, label, this); - show_info_bubble_task_ = NULL; -} - -// SecurityImageView------------------------------------------------------------ - -// static -SkBitmap* LocationBarView::SecurityImageView::lock_icon_ = NULL; -SkBitmap* LocationBarView::SecurityImageView::warning_icon_ = NULL; - -LocationBarView::SecurityImageView::SecurityImageView( - const LocationBarView* parent, - Profile* profile, - ToolbarModel* model, - const BubblePositioner* bubble_positioner) - : LocationBarImageView(bubble_positioner), - parent_(parent), - profile_(profile), - model_(model) { - if (!lock_icon_) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - lock_icon_ = rb.GetBitmapNamed(IDR_LOCK); - warning_icon_ = rb.GetBitmapNamed(IDR_WARNING); - } - SetImageShown(LOCK); -} - -LocationBarView::SecurityImageView::~SecurityImageView() { -} - -void LocationBarView::SecurityImageView::SetImageShown(Image image) { - switch (image) { - case LOCK: - SetImage(lock_icon_); - break; - case WARNING: - SetImage(warning_icon_); - break; - default: - NOTREACHED(); - break; - } -} - -bool LocationBarView::SecurityImageView::OnMousePressed( - const views::MouseEvent& event) { - TabContents* tab = parent_->GetTabContents(); - NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); - if (!nav_entry) { - NOTREACHED(); - return true; - } - tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); - return true; -} - -void LocationBarView::SecurityImageView::ShowInfoBubble() { - std::wstring text; - model_->GetIconHoverText(&text); - ShowInfoBubbleImpl(text, GetColor( - model_->GetSecurityLevel() == ToolbarModel::SECURE, - SECURITY_INFO_BUBBLE_TEXT)); -} - // ContentSettingImageView------------------------------------------------------ LocationBarView::ContentSettingImageView::ContentSettingImageView( ContentSettingsType content_type, const LocationBarView* parent, - Profile* profile, - const BubblePositioner* bubble_positioner) + Profile* profile) : content_setting_image_model_( ContentSettingImageModel::CreateContentSettingImageModel( content_type)), parent_(parent), profile_(profile), - info_bubble_(NULL), - bubble_positioner_(bubble_positioner) { + info_bubble_(NULL) { } LocationBarView::ContentSettingImageView::~ContentSettingImageView() { @@ -1351,29 +1248,39 @@ void LocationBarView::ContentSettingImageView::UpdateFromTabContents( const TabContents* tab_contents) { int old_icon = content_setting_image_model_->get_icon(); content_setting_image_model_->UpdateFromTabContents(tab_contents); - if (content_setting_image_model_->is_visible()) { - if (old_icon != content_setting_image_model_->get_icon()) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - SetImage(rb.GetBitmapNamed(content_setting_image_model_->get_icon())); - } - SetTooltipText(UTF8ToWide(content_setting_image_model_->get_tooltip())); - SetVisible(true); - } else { + if (!content_setting_image_model_->is_visible()) { SetVisible(false); + return; + } + if (old_icon != content_setting_image_model_->get_icon()) { + SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed( + content_setting_image_model_->get_icon())); } + SetTooltipText(UTF8ToWide(content_setting_image_model_->get_tooltip())); + SetVisible(true); } bool LocationBarView::ContentSettingImageView::OnMousePressed( const views::MouseEvent& event) { - gfx::Rect bounds(bubble_positioner_->GetLocationStackBounds()); - gfx::Point location; - views::View::ConvertPointToScreen(this, &location); - bounds.set_x(location.x()); - bounds.set_width(width()); + // We want to show the bubble on mouse release; that is the standard behavior + // for buttons. + return true; +} + +void LocationBarView::ContentSettingImageView::OnMouseReleased( + const views::MouseEvent& event, + bool canceled) { + if (canceled || !HitTest(event.location())) + return; TabContents* tab_contents = parent_->GetTabContents(); if (!tab_contents) - return true; + return; + + gfx::Rect screen_bounds(GetImageBounds()); + gfx::Point origin(screen_bounds.origin()); + views::View::ConvertPointToScreen(this, &origin); + screen_bounds.set_origin(origin); ContentSettingBubbleContents* bubble_contents = new ContentSettingBubbleContents( ContentSettingBubbleModel::CreateContentSettingBubbleModel( @@ -1381,9 +1288,9 @@ bool LocationBarView::ContentSettingImageView::OnMousePressed( content_setting_image_model_->get_content_settings_type()), profile_, tab_contents); DCHECK(!info_bubble_); - info_bubble_ = InfoBubble::Show(GetWindow(), bounds, bubble_contents, this); + info_bubble_ = + InfoBubble::Show(GetWindow(), screen_bounds, bubble_contents, this); bubble_contents->set_info_bubble(info_bubble_); - return true; } void LocationBarView::ContentSettingImageView::VisibilityChanged( @@ -1408,10 +1315,8 @@ bool LocationBarView::ContentSettingImageView::CloseOnEscape() { LocationBarView::PageActionImageView::PageActionImageView( LocationBarView* owner, Profile* profile, - ExtensionAction* page_action, - const BubblePositioner* bubble_positioner) - : LocationBarImageView(bubble_positioner), - owner_(owner), + ExtensionAction* page_action) + : owner_(owner), profile_(profile), page_action_(page_action), ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), @@ -1468,19 +1373,17 @@ void LocationBarView::PageActionImageView::ExecuteAction(int button, if (popup_showing) return; - View* parent = GetParent(); - gfx::Point origin; - View::ConvertPointToScreen(parent, &origin); - gfx::Rect rect = parent->bounds(); - rect.set_x(origin.x()); - rect.set_y(origin.y()); + gfx::Rect screen_bounds(GetImageBounds()); + gfx::Point origin(screen_bounds.origin()); + View::ConvertPointToScreen(this, &origin); + screen_bounds.set_origin(origin); popup_ = ExtensionPopup::Show( page_action_->GetPopupUrl(current_tab_id_), browser, browser->profile(), browser->window()->GetNativeHandle(), - rect, + screen_bounds, BubbleBorder::TOP_RIGHT, true, // Activate the popup window. inspect_with_devtools, @@ -1493,24 +1396,17 @@ void LocationBarView::PageActionImageView::ExecuteAction(int button, } } -void LocationBarView::PageActionImageView::OnMouseMoved( - const views::MouseEvent& event) { - // PageActionImageView uses normal tooltips rather than the info bubble, - // so just do nothing here rather than letting LocationBarImageView start - // its hover timer. -} - bool LocationBarView::PageActionImageView::OnMousePressed( const views::MouseEvent& event) { - // We are interested in capturing mouse messages, but we want want to wait - // until mouse-up because we might show a context menu. Doing so on mouse-down - // causes weird bugs like http://crbug.com/33155. + // We want to show the bubble on mouse release; that is the standard behavior + // for buttons. (Also, triggering on mouse press causes bugs like + // http://crbug.com/33155.) return true; } void LocationBarView::PageActionImageView::OnMouseReleased( const views::MouseEvent& event, bool canceled) { - if (canceled) + if (canceled || !HitTest(event.location())) return; int button = -1; @@ -1520,30 +1416,26 @@ void LocationBarView::PageActionImageView::OnMouseReleased( button = 2; } else if (event.IsRightMouseButton()) { // Get the top left point of this button in screen coordinates. - gfx::Point point = gfx::Point(0, 0); - ConvertPointToScreen(this, &point); + gfx::Point menu_origin; + ConvertPointToScreen(this, &menu_origin); // Make the menu appear below the button. - point.Offset(0, height()); + menu_origin.Offset(0, height()); Extension* extension = profile_->GetExtensionsService()->GetExtensionById( page_action()->extension_id(), false); Browser* browser = BrowserView::GetBrowserViewForNativeWindow( platform_util::GetTopLevel(GetWidget()->GetNativeView()))->browser(); - context_menu_contents_ = new ExtensionContextMenuModel( - extension, browser, this); + context_menu_contents_ = + new ExtensionContextMenuModel(extension, browser, this); context_menu_menu_.reset(new views::Menu2(context_menu_contents_.get())); - context_menu_menu_->RunContextMenuAt(point); + context_menu_menu_->RunContextMenuAt(menu_origin); return; } ExecuteAction(button, false); // inspect_with_devtools } -void LocationBarView::PageActionImageView::ShowInfoBubble() { - ShowInfoBubbleImpl(ASCIIToWide(tooltip_), GetColor(false, TEXT)); -} - void LocationBarView::PageActionImageView::OnImageLoaded( SkBitmap* image, ExtensionResource resource, int index) { // We loaded icons()->size() icons, plus one extra if the page action had @@ -1572,8 +1464,8 @@ void LocationBarView::PageActionImageView::UpdateVisibility( current_tab_id_ = ExtensionTabUtil::GetTabId(contents); current_url_ = url; - bool visible = preview_enabled_ || - page_action_->GetIsVisible(current_tab_id_); + bool visible = + preview_enabled_ || page_action_->GetIsVisible(current_tab_id_); if (visible) { // Set the tooltip. tooltip_ = page_action_->GetTitle(current_tab_id_); @@ -1629,6 +1521,54 @@ void LocationBarView::PageActionImageView::HidePopup() { popup_->Close(); } +// StarView--------------------------------------------------------------------- + +LocationBarView::StarView::StarView(CommandUpdater* command_updater) + : command_updater_(command_updater) { + SetID(VIEW_ID_STAR_BUTTON); + SetToggled(false); +} + +LocationBarView::StarView::~StarView() { +} + +void LocationBarView::StarView::SetToggled(bool on) { + SetTooltipText(l10n_util::GetString( + on ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR)); + // Since StarView is an ImageView, the SetTooltipText changes the accessible + // name. To keep the accessible name unchanged, we need to set the accessible + // name right after we modify the tooltip text for this view. + SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_STAR)); + SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed( + on ? IDR_OMNIBOX_STAR_LIT : IDR_OMNIBOX_STAR)); +} + +bool LocationBarView::StarView::GetAccessibleRole( + AccessibilityTypes::Role* role) { + *role = AccessibilityTypes::ROLE_PUSHBUTTON; + return true; +} + +bool LocationBarView::StarView::OnMousePressed(const views::MouseEvent& event) { + // We want to show the bubble on mouse release; that is the standard behavior + // for buttons. + return true; +} + +void LocationBarView::StarView::OnMouseReleased(const views::MouseEvent& event, + bool canceled) { + if (!canceled && HitTest(event.location())) + command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE); +} + +void LocationBarView::StarView::InfoBubbleClosing(InfoBubble* info_bubble, + bool closed_by_escape) { +} + +bool LocationBarView::StarView::CloseOnEscape() { + return true; +} + //////////////////////////////////////////////////////////////////////////////// // LocationBarView, LocationBar implementation: |