Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(995)

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 10494004: Implements a zoom icon in the Omnibox for Views. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 30 matching lines...) Expand all
41 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" 41 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h"
42 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" 42 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
45 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 45 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
46 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 46 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
47 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" 47 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h"
48 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" 48 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
49 #include "chrome/browser/ui/views/location_bar/star_view.h" 49 #include "chrome/browser/ui/views/location_bar/star_view.h"
50 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" 50 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h"
51 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
52 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
51 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 53 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
52 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" 54 #include "chrome/browser/ui/views/omnibox/omnibox_views.h"
53 #include "chrome/browser/ui/webui/instant_ui.h" 55 #include "chrome/browser/ui/webui/instant_ui.h"
54 #include "chrome/common/chrome_notification_types.h" 56 #include "chrome/common/chrome_notification_types.h"
55 #include "chrome/common/chrome_switches.h" 57 #include "chrome/common/chrome_switches.h"
56 #include "chrome/common/extensions/extension_switch_utils.h" 58 #include "chrome/common/extensions/extension_switch_utils.h"
57 #include "chrome/common/pref_names.h" 59 #include "chrome/common/pref_names.h"
58 #include "content/public/browser/notification_service.h" 60 #include "content/public/browser/notification_service.h"
59 #include "content/public/browser/render_widget_host_view.h" 61 #include "content/public/browser/render_widget_host_view.h"
60 #include "content/public/browser/web_contents.h" 62 #include "content/public/browser/web_contents.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 disposition_(CURRENT_TAB), 173 disposition_(CURRENT_TAB),
172 transition_(content::PageTransitionFromInt( 174 transition_(content::PageTransitionFromInt(
173 content::PAGE_TRANSITION_TYPED | 175 content::PAGE_TRANSITION_TYPED |
174 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), 176 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)),
175 location_icon_view_(NULL), 177 location_icon_view_(NULL),
176 ev_bubble_view_(NULL), 178 ev_bubble_view_(NULL),
177 location_entry_view_(NULL), 179 location_entry_view_(NULL),
178 selected_keyword_view_(NULL), 180 selected_keyword_view_(NULL),
179 suggested_text_view_(NULL), 181 suggested_text_view_(NULL),
180 keyword_hint_view_(NULL), 182 keyword_hint_view_(NULL),
183 zoom_view_(NULL),
181 star_view_(NULL), 184 star_view_(NULL),
182 action_box_button_view_(NULL), 185 action_box_button_view_(NULL),
183 chrome_to_mobile_view_(NULL), 186 chrome_to_mobile_view_(NULL),
184 mode_(mode), 187 mode_(mode),
185 show_focus_rect_(false), 188 show_focus_rect_(false),
186 template_url_service_(NULL), 189 template_url_service_(NULL),
187 animation_offset_(0), 190 animation_offset_(0),
188 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) { 191 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) {
189 set_id(VIEW_ID_LOCATION_BAR); 192 set_id(VIEW_ID_LOCATION_BAR);
190 193
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 keyword_hint_view_->SetFont(font_); 264 keyword_hint_view_->SetFont(font_);
262 265
263 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 266 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
264 ContentSettingImageView* content_blocked_view = 267 ContentSettingImageView* content_blocked_view =
265 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this); 268 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this);
266 content_setting_views_.push_back(content_blocked_view); 269 content_setting_views_.push_back(content_blocked_view);
267 AddChildView(content_blocked_view); 270 AddChildView(content_blocked_view);
268 content_blocked_view->SetVisible(false); 271 content_blocked_view->SetVisible(false);
269 } 272 }
270 273
274 zoom_view_ = new ZoomView(model_);
275 AddChildView(zoom_view_);
276
271 if (extensions::switch_utils::IsActionBoxEnabled()) { 277 if (extensions::switch_utils::IsActionBoxEnabled()) {
272 action_box_button_view_ = new ActionBoxButtonView( 278 action_box_button_view_ = new ActionBoxButtonView(
273 ExtensionSystem::Get(profile_)->extension_service()); 279 ExtensionSystem::Get(profile_)->extension_service());
274 AddChildView(action_box_button_view_); 280 AddChildView(action_box_button_view_);
275 } else if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { 281 } else if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) {
276 // Note: condition above means that the star and ChromeToMobile icons are 282 // Note: condition above means that the star and ChromeToMobile icons are
277 // hidden in popups and in the app launcher. 283 // hidden in popups and in the app launcher.
278 star_view_ = new StarView(command_updater_); 284 star_view_ = new StarView(command_updater_);
279 AddChildView(star_view_); 285 AddChildView(star_view_);
280 star_view_->SetVisible(true); 286 star_view_->SetVisible(true);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // Fade in so the icons don't pop. 389 // Fade in so the icons don't pop.
384 StartFadeAnimation(); 390 StartFadeAnimation();
385 } else { 391 } else {
386 // Cancel any pending animations; switch to the final state immediately. 392 // Cancel any pending animations; switch to the final state immediately.
387 StopFadeAnimation(); 393 StopFadeAnimation();
388 } 394 }
389 #endif 395 #endif
390 } 396 }
391 397
392 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { 398 void LocationBarView::Update(const WebContents* tab_for_state_restoring) {
399 RefreshContentSettingViews();
400 zoom_view_->Update();
401 RefreshPageActionViews();
402
393 bool star_enabled = star_view_ && !model_->input_in_progress() && 403 bool star_enabled = star_view_ && !model_->input_in_progress() &&
394 edit_bookmarks_enabled_.GetValue(); 404 edit_bookmarks_enabled_.GetValue();
395 405
396 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); 406 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
397 if (star_view_) 407 if (star_view_)
398 star_view_->SetVisible(star_enabled); 408 star_view_->SetVisible(star_enabled);
399 409
400 bool enabled = chrome_to_mobile_view_ && !model_->input_in_progress() && 410 bool enabled = chrome_to_mobile_view_ && !model_->input_in_progress() &&
401 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasDevices(); 411 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasDevices();
402 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); 412 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled);
403 413
404 RefreshContentSettingViews();
405 RefreshPageActionViews();
406 // Don't Update in app launcher mode so that the location entry does not show 414 // Don't Update in app launcher mode so that the location entry does not show
407 // a URL or security background. 415 // a URL or security background.
408 if (mode_ != APP_LAUNCHER) 416 if (mode_ != APP_LAUNCHER)
409 location_entry_->Update(tab_for_state_restoring); 417 location_entry_->Update(tab_for_state_restoring);
410 OnChanged(); 418 OnChanged();
411 } 419 }
412 420
413 void LocationBarView::UpdateContentSettingsIcons() { 421 void LocationBarView::UpdateContentSettingsIcons() {
414 RefreshContentSettingViews(); 422 RefreshContentSettingViews();
415 423
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 496
489 void LocationBarView::SetStarToggled(bool on) { 497 void LocationBarView::SetStarToggled(bool on) {
490 if (star_view_) 498 if (star_view_)
491 star_view_->SetToggled(on); 499 star_view_->SetToggled(on);
492 } 500 }
493 501
494 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { 502 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) {
495 browser::ShowBookmarkBubbleView(star_view_, profile_, url, newly_bookmarked); 503 browser::ShowBookmarkBubbleView(star_view_, profile_, url, newly_bookmarked);
496 } 504 }
497 505
506 void LocationBarView::SetZoomIconTooltipPercent(int zoom_percent) {
507 zoom_view_->SetZoomIconTooltipPercent(zoom_percent);
508 }
509
510 void LocationBarView::SetZoomIconState(
511 ZoomController::ZoomIconState zoom_icon_state) {
512 zoom_view_->SetZoomIconState(zoom_icon_state);
513
514 Layout();
515 SchedulePaint();
516 }
517
518 void LocationBarView::ShowZoomBubble(int zoom_percent) {
519 ZoomBubbleView::ShowBubble(zoom_view_, zoom_percent, true);
520 }
521
498 void LocationBarView::ShowChromeToMobileBubble() { 522 void LocationBarView::ShowChromeToMobileBubble() {
499 Browser* browser = GetBrowserFromDelegate(delegate_); 523 Browser* browser = GetBrowserFromDelegate(delegate_);
500 browser::ShowChromeToMobileBubbleView(chrome_to_mobile_view_, browser); 524 browser::ShowChromeToMobileBubbleView(chrome_to_mobile_view_, browser);
501 } 525 }
502 526
503 gfx::Point LocationBarView::GetLocationEntryOrigin() const { 527 gfx::Point LocationBarView::GetLocationEntryOrigin() const {
504 gfx::Point origin(location_entry_view_->bounds().origin()); 528 gfx::Point origin(location_entry_view_->bounds().origin());
505 // If the UI layout is RTL, the coordinate system is not transformed and 529 // If the UI layout is RTL, the coordinate system is not transformed and
506 // therefore we need to adjust the X coordinate so that bubble appears on the 530 // therefore we need to adjust the X coordinate so that bubble appears on the
507 // right hand side of the location bar. 531 // right hand side of the location bar.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 // We'll adjust this width and take it out of |entry_width| below. 650 // We'll adjust this width and take it out of |entry_width| below.
627 } else { 651 } else {
628 location_icon_view_->SetVisible(true); 652 location_icon_view_->SetVisible(true);
629 location_icon_width = location_icon_view_->GetPreferredSize().width(); 653 location_icon_width = location_icon_view_->GetPreferredSize().width();
630 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + 654 entry_width -= (kEdgeThickness + GetEdgeItemPadding() +
631 location_icon_width + kItemEditPadding); 655 location_icon_width + kItemEditPadding);
632 } 656 }
633 657
634 if (star_view_ && star_view_->visible()) 658 if (star_view_ && star_view_->visible())
635 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); 659 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding();
636 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) 660 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) {
637 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + 661 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() +
638 GetItemPadding(); 662 GetItemPadding();
663 }
639 int action_box_button_width = location_height; 664 int action_box_button_width = location_height;
640 if (action_box_button_view_) 665 if (action_box_button_view_)
641 entry_width -= action_box_button_width + GetItemPadding(); 666 entry_width -= action_box_button_width + GetItemPadding();
642 for (PageActionViews::const_iterator i(page_action_views_.begin()); 667 for (PageActionViews::const_iterator i(page_action_views_.begin());
643 i != page_action_views_.end(); ++i) { 668 i != page_action_views_.end(); ++i) {
644 if ((*i)->visible()) 669 if ((*i)->visible())
645 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); 670 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding());
646 } 671 }
672 if (zoom_view_->visible())
673 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding();
647 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 674 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
648 i != content_setting_views_.end(); ++i) { 675 i != content_setting_views_.end(); ++i) {
649 if ((*i)->visible()) 676 if ((*i)->visible())
650 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); 677 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding());
651 } 678 }
652 // The gap between the edit and whatever is to its right is shortened. 679 // The gap between the edit and whatever is to its right is shortened.
653 entry_width += kEditInternalSpace; 680 entry_width += kEditInternalSpace;
654 681
655 // Size the EV bubble after taking star/ChromeToMobile/page actions/content 682 // Size the EV bubble after taking star/ChromeToMobile/page actions/content
656 // settings out of |entry_width| so we won't take too much space. 683 // settings out of |entry_width| so we won't take too much space.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 for (PageActionViews::const_iterator i(page_action_views_.begin()); 758 for (PageActionViews::const_iterator i(page_action_views_.begin());
732 i != page_action_views_.end(); ++i) { 759 i != page_action_views_.end(); ++i) {
733 if ((*i)->visible()) { 760 if ((*i)->visible()) {
734 offset += (*i)->GetBuiltInHorizontalPadding(); 761 offset += (*i)->GetBuiltInHorizontalPadding();
735 int page_action_width = (*i)->GetPreferredSize().width(); 762 int page_action_width = (*i)->GetPreferredSize().width();
736 offset -= page_action_width; 763 offset -= page_action_width;
737 (*i)->SetBounds(offset, location_y, page_action_width, location_height); 764 (*i)->SetBounds(offset, location_y, page_action_width, location_height);
738 offset -= GetItemPadding() - (*i)->GetBuiltInHorizontalPadding(); 765 offset -= GetItemPadding() - (*i)->GetBuiltInHorizontalPadding();
739 } 766 }
740 } 767 }
768
769 if (zoom_view_->visible()) {
770 int zoom_width = zoom_view_->GetPreferredSize().width();
771 offset -= zoom_width;
772 zoom_view_->SetBounds(offset, location_y, zoom_width, location_height);
773 offset -= GetItemPadding();
774 }
775
741 // We use a reverse_iterator here because we're laying out the views from 776 // We use a reverse_iterator here because we're laying out the views from
742 // right to left but in the vector they're ordered left to right. 777 // right to left but in the vector they're ordered left to right.
743 for (ContentSettingViews::const_reverse_iterator 778 for (ContentSettingViews::const_reverse_iterator
744 i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); 779 i(content_setting_views_.rbegin()); i != content_setting_views_.rend();
745 ++i) { 780 ++i) {
746 if ((*i)->visible()) { 781 if ((*i)->visible()) {
747 offset += (*i)->GetBuiltInHorizontalPadding(); 782 offset += (*i)->GetBuiltInHorizontalPadding();
748 int content_blocked_width = (*i)->GetPreferredSize().width(); 783 int content_blocked_width = (*i)->GetPreferredSize().width();
749 offset -= content_blocked_width; 784 offset -= content_blocked_width;
750 (*i)->SetBounds(offset, location_y, content_blocked_width, 785 (*i)->SetBounds(offset, location_y, content_blocked_width,
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 } 1492 }
1458 1493
1459 void LocationBarView::CleanupFadeAnimation() { 1494 void LocationBarView::CleanupFadeAnimation() {
1460 // Since we're no longer animating we don't need our layer. 1495 // Since we're no longer animating we don't need our layer.
1461 SetPaintToLayer(false); 1496 SetPaintToLayer(false);
1462 // Bubble labels don't need a transparent background anymore. 1497 // Bubble labels don't need a transparent background anymore.
1463 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1498 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1464 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1499 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1465 } 1500 }
1466 #endif // USE_AURA 1501 #endif // USE_AURA
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/location_bar/zoom_bubble_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698