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

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

Issue 10885024: Integrate Chrome To Mobile with Action Box UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nil/NULL checks in ChromeToMobileBubbleController. Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 10 #include "base/command_line.h"
(...skipping 20 matching lines...) Expand all
31 #include "chrome/browser/ui/browser_tabstrip.h" 31 #include "chrome/browser/ui/browser_tabstrip.h"
32 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 32 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
33 #include "chrome/browser/ui/search/search.h" 33 #include "chrome/browser/ui/search/search.h"
34 #include "chrome/browser/ui/search/search_model.h" 34 #include "chrome/browser/ui/search/search_model.h"
35 #include "chrome/browser/ui/search/search_types.h" 35 #include "chrome/browser/ui/search/search_types.h"
36 #include "chrome/browser/ui/search/search_ui.h" 36 #include "chrome/browser/ui/search/search_ui.h"
37 #include "chrome/browser/ui/tab_contents/tab_contents.h" 37 #include "chrome/browser/ui/tab_contents/tab_contents.h"
38 #include "chrome/browser/ui/view_ids.h" 38 #include "chrome/browser/ui/view_ids.h"
39 #include "chrome/browser/ui/views/browser_dialogs.h" 39 #include "chrome/browser/ui/views/browser_dialogs.h"
40 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" 40 #include "chrome/browser/ui/views/location_bar/action_box_button_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" 41 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 42 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 43 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
45 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 44 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
46 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 45 #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" 46 #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" 47 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
49 #include "chrome/browser/ui/views/location_bar/star_view.h" 48 #include "chrome/browser/ui/views/location_bar/star_view.h"
50 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" 49 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h"
51 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" 50 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), 184 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)),
186 location_icon_view_(NULL), 185 location_icon_view_(NULL),
187 ev_bubble_view_(NULL), 186 ev_bubble_view_(NULL),
188 location_entry_view_(NULL), 187 location_entry_view_(NULL),
189 selected_keyword_view_(NULL), 188 selected_keyword_view_(NULL),
190 suggested_text_view_(NULL), 189 suggested_text_view_(NULL),
191 keyword_hint_view_(NULL), 190 keyword_hint_view_(NULL),
192 zoom_view_(NULL), 191 zoom_view_(NULL),
193 star_view_(NULL), 192 star_view_(NULL),
194 action_box_button_view_(NULL), 193 action_box_button_view_(NULL),
195 chrome_to_mobile_view_(NULL),
196 mode_(mode), 194 mode_(mode),
197 show_focus_rect_(false), 195 show_focus_rect_(false),
198 template_url_service_(NULL), 196 template_url_service_(NULL),
199 animation_offset_(0), 197 animation_offset_(0),
200 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) { 198 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) {
201 set_id(VIEW_ID_LOCATION_BAR); 199 set_id(VIEW_ID_LOCATION_BAR);
202 200
203 if (mode_ == NORMAL) { 201 if (mode_ == NORMAL) {
204 painter_.reset( 202 painter_.reset(
205 views::Painter::CreateImagePainter( 203 views::Painter::CreateImagePainter(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this); 275 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this);
278 content_setting_views_.push_back(content_blocked_view); 276 content_setting_views_.push_back(content_blocked_view);
279 AddChildView(content_blocked_view); 277 AddChildView(content_blocked_view);
280 content_blocked_view->SetVisible(false); 278 content_blocked_view->SetVisible(false);
281 } 279 }
282 280
283 zoom_view_ = new ZoomView(model_, delegate_); 281 zoom_view_ = new ZoomView(model_, delegate_);
284 AddChildView(zoom_view_); 282 AddChildView(zoom_view_);
285 283
286 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { 284 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) {
287 // Note: condition above means that the star and ChromeToMobile icons are 285 // Note: condition above means that the star icon is hidden in popups and in
288 // hidden in popups and in the app launcher. 286 // the app launcher.
289 star_view_ = new StarView(command_updater_); 287 star_view_ = new StarView(command_updater_);
290 AddChildView(star_view_); 288 AddChildView(star_view_);
291 star_view_->SetVisible(true); 289 star_view_->SetVisible(true);
292
293 // Disable Chrome To Mobile for off-the-record and non-synced profiles,
294 // or if the feature is disabled by a command line flag or chrome://flags.
295 if (!profile_->IsOffTheRecord() && profile_->IsSyncAccessible() &&
296 ChromeToMobileService::IsChromeToMobileEnabled()) {
297 chrome_to_mobile_view_ = new ChromeToMobileView(this, command_updater_);
298 AddChildView(chrome_to_mobile_view_);
299 chrome_to_mobile_view_->SetVisible(
300 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasMobiles());
301 }
302 } 290 }
303 if (ActionBoxButtonView::IsActionBoxEnabled() && browser_) { 291 if (ActionBoxButtonView::IsActionBoxEnabled() && browser_) {
304 action_box_button_view_ = new ActionBoxButtonView(browser_, profile_); 292 action_box_button_view_ = new ActionBoxButtonView(browser_, profile_);
305 AddChildView(action_box_button_view_); 293 AddChildView(action_box_button_view_);
306 if (star_view_) 294 if (star_view_)
307 star_view_->SetVisible(false); 295 star_view_->SetVisible(false);
308 } 296 }
309 297
310 registrar_.Add(this, 298 registrar_.Add(this,
311 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, 299 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 RefreshZoomView(); 399 RefreshZoomView();
412 RefreshPageActionViews(); 400 RefreshPageActionViews();
413 401
414 bool star_enabled = star_view_ && !model_->input_in_progress() && 402 bool star_enabled = star_view_ && !model_->input_in_progress() &&
415 edit_bookmarks_enabled_.GetValue(); 403 edit_bookmarks_enabled_.GetValue();
416 404
417 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); 405 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
418 if (star_view_ && !ActionBoxButtonView::IsActionBoxEnabled()) 406 if (star_view_ && !ActionBoxButtonView::IsActionBoxEnabled())
419 star_view_->SetVisible(star_enabled); 407 star_view_->SetVisible(star_enabled);
420 408
421 bool enabled = chrome_to_mobile_view_ && !model_->input_in_progress() && 409 bool enabled = ChromeToMobileService::IsChromeToMobileEnabled() &&
410 !model_->input_in_progress() &&
422 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasMobiles(); 411 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasMobiles();
423 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); 412 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled);
424 413
425 // 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
426 // a URL or security background. 415 // a URL or security background.
427 if (mode_ != APP_LAUNCHER) 416 if (mode_ != APP_LAUNCHER)
428 location_entry_->Update(tab_for_state_restoring); 417 location_entry_->Update(tab_for_state_restoring);
429 OnChanged(); 418 OnChanged();
430 } 419 }
431 420
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 } 526 }
538 527
539 void LocationBarView::RefreshZoomView() { 528 void LocationBarView::RefreshZoomView() {
540 DCHECK(zoom_view_); 529 DCHECK(zoom_view_);
541 TabContents* tab_contents = GetTabContents(); 530 TabContents* tab_contents = GetTabContents();
542 if (tab_contents) 531 if (tab_contents)
543 zoom_view_->Update(tab_contents->zoom_controller()); 532 zoom_view_->Update(tab_contents->zoom_controller());
544 } 533 }
545 534
546 void LocationBarView::ShowChromeToMobileBubble() { 535 void LocationBarView::ShowChromeToMobileBubble() {
547 Browser* browser = GetBrowserFromDelegate(delegate_); 536 chrome::ShowChromeToMobileBubbleView(action_box_button_view_,
548 chrome::ShowChromeToMobileBubbleView(chrome_to_mobile_view_, browser); 537 GetBrowserFromDelegate(delegate_));
549 } 538 }
550 539
551 gfx::Point LocationBarView::GetLocationEntryOrigin() const { 540 gfx::Point LocationBarView::GetLocationEntryOrigin() const {
552 gfx::Point origin(location_entry_view_->bounds().origin()); 541 gfx::Point origin(location_entry_view_->bounds().origin());
553 // If the UI layout is RTL, the coordinate system is not transformed and 542 // If the UI layout is RTL, the coordinate system is not transformed and
554 // therefore we need to adjust the X coordinate so that bubble appears on the 543 // therefore we need to adjust the X coordinate so that bubble appears on the
555 // right hand side of the location bar. 544 // right hand side of the location bar.
556 if (base::i18n::IsRTL()) 545 if (base::i18n::IsRTL())
557 origin.set_x(width() - origin.x()); 546 origin.set_x(width() - origin.x());
558 views::View::ConvertPointToScreen(this, &origin); 547 views::View::ConvertPointToScreen(this, &origin);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 // We'll adjust this width and take it out of |entry_width| below. 663 // We'll adjust this width and take it out of |entry_width| below.
675 } else { 664 } else {
676 location_icon_view_->SetVisible(true); 665 location_icon_view_->SetVisible(true);
677 location_icon_width = location_icon_view_->GetPreferredSize().width(); 666 location_icon_width = location_icon_view_->GetPreferredSize().width();
678 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + 667 entry_width -= (kEdgeThickness + GetEdgeItemPadding() +
679 location_icon_width + kItemEditPadding); 668 location_icon_width + kItemEditPadding);
680 } 669 }
681 670
682 if (star_view_ && star_view_->visible()) 671 if (star_view_ && star_view_->visible())
683 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); 672 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding();
684 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) {
685 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() +
686 GetItemPadding();
687 }
688 int action_box_button_width = location_height; 673 int action_box_button_width = location_height;
689 if (action_box_button_view_) 674 if (action_box_button_view_)
690 entry_width -= action_box_button_width + GetItemPadding(); 675 entry_width -= action_box_button_width + GetItemPadding();
691 for (PageActionViews::const_iterator i(page_action_views_.begin()); 676 for (PageActionViews::const_iterator i(page_action_views_.begin());
692 i != page_action_views_.end(); ++i) { 677 i != page_action_views_.end(); ++i) {
693 if ((*i)->visible()) 678 if ((*i)->visible())
694 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); 679 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding());
695 } 680 }
696 if (zoom_view_->visible()) 681 if (zoom_view_->visible())
697 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding(); 682 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding();
698 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 683 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
699 i != content_setting_views_.end(); ++i) { 684 i != content_setting_views_.end(); ++i) {
700 if ((*i)->visible()) 685 if ((*i)->visible())
701 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); 686 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding());
702 } 687 }
703 // The gap between the edit and whatever is to its right is shortened. 688 // The gap between the edit and whatever is to its right is shortened.
704 entry_width += kEditInternalSpace; 689 entry_width += kEditInternalSpace;
705 690
706 // Size the EV bubble after taking star/ChromeToMobile/page actions/content 691 // Size the EV bubble after taking star/page actions/content settings out of
707 // settings out of |entry_width| so we won't take too much space. 692 // |entry_width| so we won't take too much space.
708 if (ev_bubble_width) { 693 if (ev_bubble_width) {
709 // Try to elide the bubble to be no larger than half the total available 694 // Try to elide the bubble to be no larger than half the total available
710 // space, but never elide it any smaller than 150 px. 695 // space, but never elide it any smaller than 150 px.
711 static const int kMinElidedBubbleWidth = 150; 696 static const int kMinElidedBubbleWidth = 150;
712 static const double kMaxBubbleFraction = 0.5; 697 static const double kMaxBubbleFraction = 0.5;
713 const int total_padding = 698 const int total_padding =
714 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding; 699 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding;
715 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, 700 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth,
716 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction))); 701 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction)));
717 entry_width -= (total_padding + ev_bubble_width); 702 entry_width -= (total_padding + ev_bubble_width);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 } 745 }
761 746
762 if (star_view_ && star_view_->visible()) { 747 if (star_view_ && star_view_->visible()) {
763 offset += star_view_->GetBuiltInHorizontalPadding(); 748 offset += star_view_->GetBuiltInHorizontalPadding();
764 int star_width = star_view_->GetPreferredSize().width(); 749 int star_width = star_view_->GetPreferredSize().width();
765 offset -= star_width; 750 offset -= star_width;
766 star_view_->SetBounds(offset, location_y, star_width, location_height); 751 star_view_->SetBounds(offset, location_y, star_width, location_height);
767 offset -= GetItemPadding() - star_view_->GetBuiltInHorizontalPadding(); 752 offset -= GetItemPadding() - star_view_->GetBuiltInHorizontalPadding();
768 } 753 }
769 754
770 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) {
771 offset += chrome_to_mobile_view_->GetBuiltInHorizontalPadding();
772 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width();
773 offset -= icon_width;
774 chrome_to_mobile_view_->SetBounds(offset, location_y,
775 icon_width, location_height);
776 offset -= GetItemPadding() -
777 chrome_to_mobile_view_->GetBuiltInHorizontalPadding();
778 }
779
780 for (PageActionViews::const_iterator i(page_action_views_.begin()); 755 for (PageActionViews::const_iterator i(page_action_views_.begin());
781 i != page_action_views_.end(); ++i) { 756 i != page_action_views_.end(); ++i) {
782 if ((*i)->visible()) { 757 if ((*i)->visible()) {
783 offset += (*i)->GetBuiltInHorizontalPadding(); 758 offset += (*i)->GetBuiltInHorizontalPadding();
784 int page_action_width = (*i)->GetPreferredSize().width(); 759 int page_action_width = (*i)->GetPreferredSize().width();
785 offset -= page_action_width; 760 offset -= page_action_width;
786 (*i)->SetBounds(offset, location_y, page_action_width, location_height); 761 (*i)->SetBounds(offset, location_y, page_action_width, location_height);
787 offset -= GetItemPadding() - (*i)->GetBuiltInHorizontalPadding(); 762 offset -= GetItemPadding() - (*i)->GetBuiltInHorizontalPadding();
788 } 763 }
789 } 764 }
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 new_page_actions = controller->GetCurrentActions(); 1117 new_page_actions = controller->GetCurrentActions();
1143 } 1118 }
1144 1119
1145 // On startup we sometimes haven't loaded any extensions. This makes sure 1120 // On startup we sometimes haven't loaded any extensions. This makes sure
1146 // we catch up when the extensions (and any page actions) load. 1121 // we catch up when the extensions (and any page actions) load.
1147 if (page_actions_ != new_page_actions) { 1122 if (page_actions_ != new_page_actions) {
1148 page_actions_.swap(new_page_actions); 1123 page_actions_.swap(new_page_actions);
1149 DeletePageActionViews(); // Delete the old views (if any). 1124 DeletePageActionViews(); // Delete the old views (if any).
1150 1125
1151 page_action_views_.resize(page_actions_.size()); 1126 page_action_views_.resize(page_actions_.size());
1152 View* right_anchor = chrome_to_mobile_view_; 1127 View* right_anchor = star_view_;
1153 if (!right_anchor)
1154 right_anchor = star_view_;
1155 if (!right_anchor) 1128 if (!right_anchor)
1156 right_anchor = action_box_button_view_; 1129 right_anchor = action_box_button_view_;
1157 DCHECK(right_anchor); 1130 DCHECK(right_anchor);
1158 1131
1159 // Add the page actions in reverse order, so that the child views are 1132 // Add the page actions in reverse order, so that the child views are
1160 // inserted in left-to-right order for accessibility. 1133 // inserted in left-to-right order for accessibility.
1161 for (int i = page_actions_.size() - 1; i >= 0; --i) { 1134 for (int i = page_actions_.size() - 1; i >= 0; --i) {
1162 page_action_views_[i] = new PageActionWithBadgeView( 1135 page_action_views_[i] = new PageActionWithBadgeView(
1163 delegate_->CreatePageActionImageView(this, page_actions_[i])); 1136 delegate_->CreatePageActionImageView(this, page_actions_[i]));
1164 page_action_views_[i]->SetVisible(false); 1137 page_action_views_[i]->SetVisible(false);
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 } 1492 }
1520 1493
1521 void LocationBarView::CleanupFadeAnimation() { 1494 void LocationBarView::CleanupFadeAnimation() {
1522 // 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.
1523 SetPaintToLayer(false); 1496 SetPaintToLayer(false);
1524 // Bubble labels don't need a transparent background anymore. 1497 // Bubble labels don't need a transparent background anymore.
1525 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1498 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1526 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1499 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1527 } 1500 }
1528 #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/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698