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

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

Issue 9443007: Add Chrome To Mobile Service and Views Page Action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Put shared CloudPrint consts/helpers in chrome/common/; use CloudPrintURL. Created 8 years, 9 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
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 #if defined(TOOLKIT_USES_GTK) 7 #if defined(TOOLKIT_USES_GTK)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <map> 12 #include <map>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "chrome/app/chrome_command_ids.h" 17 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/browser/alternate_nav_url_fetcher.h" 18 #include "chrome/browser/alternate_nav_url_fetcher.h"
19 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 19 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
20 #include "chrome/browser/chrome_to_mobile_service.h"
21 #include "chrome/browser/chrome_to_mobile_service_factory.h"
20 #include "chrome/browser/defaults.h" 22 #include "chrome/browser/defaults.h"
21 #include "chrome/browser/extensions/extension_browser_event_router.h" 23 #include "chrome/browser/extensions/extension_browser_event_router.h"
22 #include "chrome/browser/extensions/extension_service.h" 24 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/favicon/favicon_tab_helper.h" 25 #include "chrome/browser/favicon/favicon_tab_helper.h"
24 #include "chrome/browser/instant/instant_controller.h" 26 #include "chrome/browser/instant/instant_controller.h"
25 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/search_engines/template_url.h" 28 #include "chrome/browser/search_engines/template_url.h"
27 #include "chrome/browser/search_engines/template_url_service.h" 29 #include "chrome/browser/search_engines/template_url_service.h"
28 #include "chrome/browser/search_engines/template_url_service_factory.h" 30 #include "chrome/browser/search_engines/template_url_service_factory.h"
29 #include "chrome/browser/ui/browser.h" 31 #include "chrome/browser/ui/browser.h"
30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
31 #include "chrome/browser/ui/view_ids.h" 33 #include "chrome/browser/ui/view_ids.h"
32 #include "chrome/browser/ui/views/browser_dialogs.h" 34 #include "chrome/browser/ui/views/browser_dialogs.h"
33 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" 35 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
34 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 36 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
35 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 37 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
36 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 38 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
37 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 39 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
38 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" 40 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h"
39 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" 41 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
42 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h"
40 #include "chrome/browser/ui/views/location_bar/star_view.h" 43 #include "chrome/browser/ui/views/location_bar/star_view.h"
41 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 44 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
42 #include "chrome/common/chrome_notification_types.h" 45 #include "chrome/common/chrome_notification_types.h"
43 #include "chrome/common/chrome_switches.h" 46 #include "chrome/common/chrome_switches.h"
44 #include "chrome/common/pref_names.h" 47 #include "chrome/common/pref_names.h"
45 #include "content/public/browser/notification_service.h" 48 #include "content/public/browser/notification_service.h"
46 #include "content/public/browser/render_widget_host_view.h" 49 #include "content/public/browser/render_widget_host_view.h"
47 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
48 #include "grit/generated_resources.h" 51 #include "grit/generated_resources.h"
49 #include "grit/theme_resources.h" 52 #include "grit/theme_resources.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), 131 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)),
129 location_icon_view_(NULL), 132 location_icon_view_(NULL),
130 ev_bubble_view_(NULL), 133 ev_bubble_view_(NULL),
131 location_entry_view_(NULL), 134 location_entry_view_(NULL),
132 selected_keyword_view_(NULL), 135 selected_keyword_view_(NULL),
133 #if defined(OS_WIN) || defined(USE_AURA) 136 #if defined(OS_WIN) || defined(USE_AURA)
134 suggested_text_view_(NULL), 137 suggested_text_view_(NULL),
135 #endif 138 #endif
136 keyword_hint_view_(NULL), 139 keyword_hint_view_(NULL),
137 star_view_(NULL), 140 star_view_(NULL),
141 chrome_to_mobile_view_(NULL),
138 mode_(mode), 142 mode_(mode),
139 show_focus_rect_(false), 143 show_focus_rect_(false),
140 template_url_service_(NULL), 144 template_url_service_(NULL),
141 animation_offset_(0) { 145 animation_offset_(0) {
142 set_id(VIEW_ID_LOCATION_BAR); 146 set_id(VIEW_ID_LOCATION_BAR);
143 147
144 if (mode_ == NORMAL) { 148 if (mode_ == NORMAL) {
145 painter_.reset( 149 painter_.reset(
146 views::Painter::CreateImagePainter( 150 views::Painter::CreateImagePainter(
147 *ResourceBundle::GetSharedInstance().GetImageNamed( 151 *ResourceBundle::GetSharedInstance().GetImageNamed(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 keyword_hint_view_->SetFont(font_); 220 keyword_hint_view_->SetFont(font_);
217 221
218 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 222 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
219 ContentSettingImageView* content_blocked_view = 223 ContentSettingImageView* content_blocked_view =
220 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this); 224 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this);
221 content_setting_views_.push_back(content_blocked_view); 225 content_setting_views_.push_back(content_blocked_view);
222 AddChildView(content_blocked_view); 226 AddChildView(content_blocked_view);
223 content_blocked_view->SetVisible(false); 227 content_blocked_view->SetVisible(false);
224 } 228 }
225 229
226 // The star is not visible in popups and in the app launcher. 230 // Hide the star and Chrome To Mobile icons in popups and in the app launcher.
227 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { 231 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) {
228 star_view_ = new StarView(browser_->command_updater()); 232 star_view_ = new StarView(browser_->command_updater());
229 AddChildView(star_view_); 233 AddChildView(star_view_);
230 star_view_->SetVisible(true); 234 star_view_->SetVisible(true);
235
236 chrome_to_mobile_view_ =
237 new ChromeToMobileView(this, browser_->command_updater());
238 AddChildView(chrome_to_mobile_view_);
239 if (browser_->profile()->IsSyncAccessible())
240 ChromeToMobileServiceFactory::GetForProfile(browser_->profile())->
241 RequestMobileListUpdate();
231 } 242 }
232 243
233 // Initialize the location entry. We do this to avoid a black flash which is 244 // Initialize the location entry. We do this to avoid a black flash which is
234 // visible when the location entry has just been initialized. 245 // visible when the location entry has just been initialized.
235 Update(NULL); 246 Update(NULL);
236 247
237 OnChanged(); 248 OnChanged();
238 } 249 }
239 250
240 bool LocationBarView::IsInitialized() const { 251 bool LocationBarView::IsInitialized() const {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 FocusLocation(select_all); 306 FocusLocation(select_all);
296 } 307 }
297 308
298 void LocationBarView::SetAnimationOffset(int offset) { 309 void LocationBarView::SetAnimationOffset(int offset) {
299 animation_offset_ = offset; 310 animation_offset_ = offset;
300 } 311 }
301 312
302 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { 313 void LocationBarView::Update(const WebContents* tab_for_state_restoring) {
303 bool star_enabled = star_view_ && !model_->input_in_progress() && 314 bool star_enabled = star_view_ && !model_->input_in_progress() &&
304 edit_bookmarks_enabled_.GetValue(); 315 edit_bookmarks_enabled_.GetValue();
305 browser_->command_updater()->UpdateCommandEnabled( 316 CommandUpdater* command_updater = browser_->command_updater();
306 IDC_BOOKMARK_PAGE, star_enabled); 317 command_updater->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
307 if (star_view_) 318 if (star_view_)
308 star_view_->SetVisible(star_enabled); 319 star_view_->SetVisible(star_enabled);
320
321 Profile* profile = browser_->profile();
322 bool chrome_to_mobile_enabled = chrome_to_mobile_view_ &&
323 !model_->input_in_progress() && profile->IsSyncAccessible() &&
324 !ChromeToMobileServiceFactory::GetForProfile(profile)->mobiles().empty();
325 command_updater->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE,
326 chrome_to_mobile_enabled);
327
309 RefreshContentSettingViews(); 328 RefreshContentSettingViews();
310 RefreshPageActionViews(); 329 RefreshPageActionViews();
311 // Don't Update in app launcher mode so that the location entry does not show 330 // Don't Update in app launcher mode so that the location entry does not show
312 // a URL or security background. 331 // a URL or security background.
313 if (mode_ != APP_LAUNCHER) 332 if (mode_ != APP_LAUNCHER)
314 location_entry_->Update(tab_for_state_restoring); 333 location_entry_->Update(tab_for_state_restoring);
315 OnChanged(); 334 OnChanged();
316 } 335 }
317 336
318 void LocationBarView::UpdateContentSettingsIcons() { 337 void LocationBarView::UpdateContentSettingsIcons() {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 void LocationBarView::SetStarToggled(bool on) { 414 void LocationBarView::SetStarToggled(bool on) {
396 if (star_view_) 415 if (star_view_)
397 star_view_->SetToggled(on); 416 star_view_->SetToggled(on);
398 } 417 }
399 418
400 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { 419 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) {
401 browser::ShowBookmarkBubbleView(star_view_, browser_->profile(), url, 420 browser::ShowBookmarkBubbleView(star_view_, browser_->profile(), url,
402 newly_bookmarked); 421 newly_bookmarked);
403 } 422 }
404 423
424 void LocationBarView::ShowChromeToMobileBubble() {
425 ChromeToMobileServiceFactory::GetForProfile(browser_->profile())->
426 RequestMobileListUpdate();
427 browser::ShowChromeToMobileBubbleView(chrome_to_mobile_view_,
428 browser_->profile());
429 }
430
405 gfx::Point LocationBarView::GetLocationEntryOrigin() const { 431 gfx::Point LocationBarView::GetLocationEntryOrigin() const {
406 gfx::Point origin(location_entry_view_->bounds().origin()); 432 gfx::Point origin(location_entry_view_->bounds().origin());
407 // If the UI layout is RTL, the coordinate system is not transformed and 433 // If the UI layout is RTL, the coordinate system is not transformed and
408 // therefore we need to adjust the X coordinate so that bubble appears on the 434 // therefore we need to adjust the X coordinate so that bubble appears on the
409 // right hand side of the location bar. 435 // right hand side of the location bar.
410 if (base::i18n::IsRTL()) 436 if (base::i18n::IsRTL())
411 origin.set_x(width() - origin.x()); 437 origin.set_x(width() - origin.x());
412 views::View::ConvertPointToScreen(this, &origin); 438 views::View::ConvertPointToScreen(this, &origin);
413 return origin; 439 return origin;
414 } 440 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 // We'll adjust this width and take it out of |entry_width| below. 545 // We'll adjust this width and take it out of |entry_width| below.
520 } else { 546 } else {
521 location_icon_view_->SetVisible(true); 547 location_icon_view_->SetVisible(true);
522 location_icon_width = location_icon_view_->GetPreferredSize().width(); 548 location_icon_width = location_icon_view_->GetPreferredSize().width();
523 entry_width -= (kEdgeThickness + kEdgeItemPadding + location_icon_width + 549 entry_width -= (kEdgeThickness + kEdgeItemPadding + location_icon_width +
524 kItemEditPadding); 550 kItemEditPadding);
525 } 551 }
526 552
527 if (star_view_ && star_view_->visible()) 553 if (star_view_ && star_view_->visible())
528 entry_width -= star_view_->GetPreferredSize().width() + kItemPadding; 554 entry_width -= star_view_->GetPreferredSize().width() + kItemPadding;
555 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible())
556 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() +
557 kItemPadding;
529 for (PageActionViews::const_iterator i(page_action_views_.begin()); 558 for (PageActionViews::const_iterator i(page_action_views_.begin());
530 i != page_action_views_.end(); ++i) { 559 i != page_action_views_.end(); ++i) {
531 if ((*i)->visible()) 560 if ((*i)->visible())
532 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding); 561 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding);
533 } 562 }
534 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 563 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
535 i != content_setting_views_.end(); ++i) { 564 i != content_setting_views_.end(); ++i) {
536 if ((*i)->visible()) 565 if ((*i)->visible())
537 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding); 566 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding);
538 } 567 }
539 // The gap between the edit and whatever is to its right is shortened. 568 // The gap between the edit and whatever is to its right is shortened.
540 entry_width += kEditInternalSpace; 569 entry_width += kEditInternalSpace;
541 570
542 // Size the EV bubble. We do this after taking the star/page actions/content 571 // Size the EV bubble after taking star/ChromeToMobile/page actions/content
543 // settings out of |entry_width| so we won't take too much space. 572 // settings out of |entry_width| so we won't take too much space.
544 if (ev_bubble_width) { 573 if (ev_bubble_width) {
545 // Try to elide the bubble to be no larger than half the total available 574 // Try to elide the bubble to be no larger than half the total available
546 // space, but never elide it any smaller than 150 px. 575 // space, but never elide it any smaller than 150 px.
547 static const int kMinElidedBubbleWidth = 150; 576 static const int kMinElidedBubbleWidth = 150;
548 static const double kMaxBubbleFraction = 0.5; 577 static const double kMaxBubbleFraction = 0.5;
549 const int total_padding = 578 const int total_padding =
550 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding; 579 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding;
551 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, 580 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth,
552 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction))); 581 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction)));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 615
587 // Lay out items to the right of the edit field. 616 // Lay out items to the right of the edit field.
588 int offset = width() - kEdgeThickness - kEdgeItemPadding; 617 int offset = width() - kEdgeThickness - kEdgeItemPadding;
589 if (star_view_ && star_view_->visible()) { 618 if (star_view_ && star_view_->visible()) {
590 int star_width = star_view_->GetPreferredSize().width(); 619 int star_width = star_view_->GetPreferredSize().width();
591 offset -= star_width; 620 offset -= star_width;
592 star_view_->SetBounds(offset, location_y, star_width, location_height); 621 star_view_->SetBounds(offset, location_y, star_width, location_height);
593 offset -= kItemPadding; 622 offset -= kItemPadding;
594 } 623 }
595 624
625 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) {
626 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width();
627 offset -= icon_width;
628 chrome_to_mobile_view_->SetBounds(offset, location_y,
629 icon_width, location_height);
630 offset -= kItemPadding;
631 }
632
596 for (PageActionViews::const_iterator i(page_action_views_.begin()); 633 for (PageActionViews::const_iterator i(page_action_views_.begin());
597 i != page_action_views_.end(); ++i) { 634 i != page_action_views_.end(); ++i) {
598 if ((*i)->visible()) { 635 if ((*i)->visible()) {
599 int page_action_width = (*i)->GetPreferredSize().width(); 636 int page_action_width = (*i)->GetPreferredSize().width();
600 offset -= page_action_width; 637 offset -= page_action_width;
601 (*i)->SetBounds(offset, location_y, page_action_width, location_height); 638 (*i)->SetBounds(offset, location_y, page_action_width, location_height);
602 offset -= kItemPadding; 639 offset -= kItemPadding;
603 } 640 }
604 } 641 }
605 // We use a reverse_iterator here because we're laying out the views from 642 // We use a reverse_iterator here because we're laying out the views from
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 if ((*it)->page_action()) 988 if ((*it)->page_action())
952 page_actions.push_back((*it)->page_action()); 989 page_actions.push_back((*it)->page_action());
953 } 990 }
954 991
955 // On startup we sometimes haven't loaded any extensions. This makes sure 992 // On startup we sometimes haven't loaded any extensions. This makes sure
956 // we catch up when the extensions (and any page actions) load. 993 // we catch up when the extensions (and any page actions) load.
957 if (page_actions.size() != page_action_views_.size()) { 994 if (page_actions.size() != page_action_views_.size()) {
958 DeletePageActionViews(); // Delete the old views (if any). 995 DeletePageActionViews(); // Delete the old views (if any).
959 996
960 page_action_views_.resize(page_actions.size()); 997 page_action_views_.resize(page_actions.size());
998 View* view = chrome_to_mobile_view_ ? chrome_to_mobile_view_ :
999 static_cast<View*>(star_view_);
961 1000
962 // Add the page actions in reverse order, so that the child views are 1001 // Add the page actions in reverse order, so that the child views are
963 // inserted in left-to-right order for accessibility. 1002 // inserted in left-to-right order for accessibility.
964 for (int i = page_actions.size() - 1; i >= 0; --i) { 1003 for (int i = page_actions.size() - 1; i >= 0; --i) {
965 page_action_views_[i] = new PageActionWithBadgeView( 1004 page_action_views_[i] = new PageActionWithBadgeView(
966 new PageActionImageView(this, page_actions[i])); 1005 new PageActionImageView(this, page_actions[i]));
967 page_action_views_[i]->SetVisible(false); 1006 page_action_views_[i]->SetVisible(false);
968 AddChildViewAt(page_action_views_[i], GetIndexOf(star_view_)); 1007 AddChildViewAt(page_action_views_[i], GetIndexOf(view));
969 } 1008 }
970 } 1009 }
971 1010
972 WebContents* contents = GetWebContentsFromDelegate(delegate_); 1011 WebContents* contents = GetWebContentsFromDelegate(delegate_);
973 if (!page_action_views_.empty() && contents) { 1012 if (!page_action_views_.empty() && contents) {
974 GURL url = GURL(model_->GetText()); 1013 GURL url = GURL(model_->GetText());
975 1014
976 for (PageActionViews::const_iterator i(page_action_views_.begin()); 1015 for (PageActionViews::const_iterator i(page_action_views_.begin());
977 i != page_action_views_.end(); ++i) { 1016 i != page_action_views_.end(); ++i) {
978 (*i)->UpdateVisibility(model_->input_in_progress() ? NULL : contents, 1017 (*i)->UpdateVisibility(model_->input_in_progress() ? NULL : contents,
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 !suggested_text_view_->GetText().empty(); 1275 !suggested_text_view_->GetText().empty();
1237 } 1276 }
1238 1277
1239 #if !defined(USE_AURA) 1278 #if !defined(USE_AURA)
1240 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { 1279 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() {
1241 CHECK(!views::Widget::IsPureViews()); 1280 CHECK(!views::Widget::IsPureViews());
1242 return static_cast<OmniboxViewWin*>(location_entry_.get()); 1281 return static_cast<OmniboxViewWin*>(location_entry_.get());
1243 } 1282 }
1244 #endif 1283 #endif
1245 #endif 1284 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698