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

Side by Side Diff: chrome/browser/ui/gtk/location_bar_view_gtk.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/gtk/location_bar_view_gtk.h ('k') | chrome/browser/ui/gtk/view_id_util.cc » ('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/gtk/location_bar_view_gtk.h" 5 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // LocationBarViewGtk 383 // LocationBarViewGtk
384 384
385 // static 385 // static
386 const GdkColor LocationBarViewGtk::kBackgroundColor = 386 const GdkColor LocationBarViewGtk::kBackgroundColor =
387 GDK_COLOR_RGB(255, 255, 255); 387 GDK_COLOR_RGB(255, 255, 255);
388 388
389 LocationBarViewGtk::LocationBarViewGtk(Browser* browser) 389 LocationBarViewGtk::LocationBarViewGtk(Browser* browser)
390 : zoom_image_(NULL), 390 : zoom_image_(NULL),
391 star_image_(NULL), 391 star_image_(NULL),
392 starred_(false), 392 starred_(false),
393 chrome_to_mobile_image_(NULL),
394 site_type_alignment_(NULL), 393 site_type_alignment_(NULL),
395 site_type_event_box_(NULL), 394 site_type_event_box_(NULL),
396 location_icon_image_(NULL), 395 location_icon_image_(NULL),
397 drag_icon_(NULL), 396 drag_icon_(NULL),
398 enable_location_drag_(false), 397 enable_location_drag_(false),
399 security_info_label_(NULL), 398 security_info_label_(NULL),
400 web_intents_button_view_(new WebIntentsButtonViewGtk(this)), 399 web_intents_button_view_(new WebIntentsButtonViewGtk(this)),
401 tab_to_search_alignment_(NULL), 400 tab_to_search_alignment_(NULL),
402 tab_to_search_box_(NULL), 401 tab_to_search_box_(NULL),
403 tab_to_search_full_label_(NULL), 402 tab_to_search_full_label_(NULL),
(...skipping 15 matching lines...) Expand all
419 hbox_width_(0), 418 hbox_width_(0),
420 entry_box_width_(0), 419 entry_box_width_(0),
421 show_selected_keyword_(false), 420 show_selected_keyword_(false),
422 show_keyword_hint_(false) { 421 show_keyword_hint_(false) {
423 } 422 }
424 423
425 LocationBarViewGtk::~LocationBarViewGtk() { 424 LocationBarViewGtk::~LocationBarViewGtk() {
426 // All of our widgets should be children of / owned by the alignment. 425 // All of our widgets should be children of / owned by the alignment.
427 zoom_.Destroy(); 426 zoom_.Destroy();
428 star_.Destroy(); 427 star_.Destroy();
429 chrome_to_mobile_view_.Destroy();
430 hbox_.Destroy(); 428 hbox_.Destroy();
431 content_setting_hbox_.Destroy(); 429 content_setting_hbox_.Destroy();
432 page_action_hbox_.Destroy(); 430 page_action_hbox_.Destroy();
433 web_intents_hbox_.Destroy(); 431 web_intents_hbox_.Destroy();
434 } 432 }
435 433
436 void LocationBarViewGtk::Init(bool popup_window_mode) { 434 void LocationBarViewGtk::Init(bool popup_window_mode) {
437 popup_window_mode_ = popup_window_mode; 435 popup_window_mode_ = popup_window_mode;
438 436
439 Profile* profile = browser_->profile(); 437 Profile* profile = browser_->profile();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 const int kMagicActionBoxYOffset = 3; 551 const int kMagicActionBoxYOffset = 3;
554 GtkWidget* alignment = gtk_alignment_new(0, 0, 1, 1); 552 GtkWidget* alignment = gtk_alignment_new(0, 0, 1, 1);
555 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 553 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
556 0, kMagicActionBoxYOffset, 554 0, kMagicActionBoxYOffset,
557 0, kInnerPadding); 555 0, kInnerPadding);
558 gtk_container_add(GTK_CONTAINER(alignment), action_box_button_->widget()); 556 gtk_container_add(GTK_CONTAINER(alignment), action_box_button_->widget());
559 557
560 gtk_box_pack_end(GTK_BOX(hbox_.get()), alignment, 558 gtk_box_pack_end(GTK_BOX(hbox_.get()), alignment,
561 FALSE, FALSE, 0); 559 FALSE, FALSE, 0);
562 } else if (browser_defaults::bookmarks_enabled && !ShouldOnlyShowLocation()) { 560 } else if (browser_defaults::bookmarks_enabled && !ShouldOnlyShowLocation()) {
563 // Hide the star and Chrome To Mobile icons in popups, app windows, etc. 561 // Hide the star icon in popups, app windows, etc.
564 CreateStarButton(); 562 CreateStarButton();
565 gtk_box_pack_end(GTK_BOX(hbox_.get()), star_.get(), FALSE, FALSE, 0); 563 gtk_box_pack_end(GTK_BOX(hbox_.get()), star_.get(), FALSE, FALSE, 0);
566
567 // Disable Chrome To Mobile for off-the-record and non-synced profiles,
568 // or if the feature is disabled by a command line flag or chrome://flags.
569 if (!profile->IsOffTheRecord() && profile->IsSyncAccessible() &&
570 ChromeToMobileService::IsChromeToMobileEnabled()) {
571 CreateChromeToMobileButton();
572 gtk_box_pack_end(GTK_BOX(hbox_.get()), chrome_to_mobile_view_.get(),
573 FALSE, FALSE, 0);
574 command_updater_->AddCommandObserver(IDC_CHROME_TO_MOBILE_PAGE, this);
575 UpdateChromeToMobileIcon();
576 }
577 } 564 }
578 565
579 CreateZoomButton(); 566 CreateZoomButton();
580 gtk_box_pack_end(GTK_BOX(hbox_.get()), zoom_.get(), FALSE, FALSE, 0); 567 gtk_box_pack_end(GTK_BOX(hbox_.get()), zoom_.get(), FALSE, FALSE, 0);
581 568
582 content_setting_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding + 1)); 569 content_setting_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding + 1));
583 gtk_widget_set_name(content_setting_hbox_.get(), 570 gtk_widget_set_name(content_setting_hbox_.get(),
584 "chrome-content-setting-hbox"); 571 "chrome-content-setting-hbox");
585 gtk_box_pack_end(GTK_BOX(hbox_.get()), content_setting_hbox_.get(), 572 gtk_box_pack_end(GTK_BOX(hbox_.get()), content_setting_hbox_.get(),
586 FALSE, FALSE, 1); 573 FALSE, FALSE, 1);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 ++iter) { 715 ++iter) {
729 if ((*iter)->page_action() == page_action) 716 if ((*iter)->page_action() == page_action)
730 return (*iter)->widget(); 717 return (*iter)->widget();
731 } 718 }
732 return NULL; 719 return NULL;
733 } 720 }
734 721
735 void LocationBarViewGtk::Update(const WebContents* contents) { 722 void LocationBarViewGtk::Update(const WebContents* contents) {
736 UpdateZoomIcon(); 723 UpdateZoomIcon();
737 UpdateStarIcon(); 724 UpdateStarIcon();
738 UpdateChromeToMobileIcon();
739 UpdateSiteTypeArea(); 725 UpdateSiteTypeArea();
740 UpdateContentSettingsIcons(); 726 UpdateContentSettingsIcons();
741 UpdatePageActions(); 727 UpdatePageActions();
742 UpdateWebIntentsButton(); 728 UpdateWebIntentsButton();
743 location_entry_->Update(contents); 729 location_entry_->Update(contents);
744 // The security level (background color) could have changed, etc. 730 // The security level (background color) could have changed, etc.
745 if (theme_service_->UsingNativeTheme()) { 731 if (theme_service_->UsingNativeTheme()) {
746 // In GTK mode, we need our parent to redraw, as it draws the text entry 732 // In GTK mode, we need our parent to redraw, as it draws the text entry
747 // border. 733 // border.
748 gtk_widget_queue_draw(gtk_widget_get_parent(widget())); 734 gtk_widget_queue_draw(gtk_widget_get_parent(widget()));
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 } 837 }
852 838
853 void LocationBarViewGtk::CreateStarButton() { 839 void LocationBarViewGtk::CreateStarButton() {
854 star_.Own(CreateIconButton(&star_image_, 840 star_.Own(CreateIconButton(&star_image_,
855 0, 841 0,
856 VIEW_ID_STAR_BUTTON, 842 VIEW_ID_STAR_BUTTON,
857 IDS_TOOLTIP_STAR, 843 IDS_TOOLTIP_STAR,
858 OnStarButtonPressThunk)); 844 OnStarButtonPressThunk));
859 } 845 }
860 846
861 void LocationBarViewGtk::CreateChromeToMobileButton() {
862 chrome_to_mobile_view_.Own(
863 CreateIconButton(&chrome_to_mobile_image_,
864 IDR_MOBILE,
865 VIEW_ID_CHROME_TO_MOBILE_BUTTON,
866 IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP,
867 OnChromeToMobileButtonPressThunk));
868 }
869
870 void LocationBarViewGtk::OnInputInProgress(bool in_progress) { 847 void LocationBarViewGtk::OnInputInProgress(bool in_progress) {
871 // This is identical to the Windows code, except that we don't proxy the call 848 // This is identical to the Windows code, except that we don't proxy the call
872 // back through the Toolbar, and just access the model here. 849 // back through the Toolbar, and just access the model here.
873 // The edit should make sure we're only notified when something changes. 850 // The edit should make sure we're only notified when something changes.
874 DCHECK(toolbar_model_->input_in_progress() != in_progress); 851 DCHECK(toolbar_model_->input_in_progress() != in_progress);
875 852
876 toolbar_model_->set_input_in_progress(in_progress); 853 toolbar_model_->set_input_in_progress(in_progress);
877 Update(NULL); 854 Update(NULL);
878 } 855 }
879 856
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 content::Details<TabContents>(details).ptr(); 1078 content::Details<TabContents>(details).ptr();
1102 if (target_tab == GetTabContents()) 1079 if (target_tab == GetTabContents())
1103 UpdatePageActions(); 1080 UpdatePageActions();
1104 break; 1081 break;
1105 } 1082 }
1106 1083
1107 case chrome::NOTIFICATION_PREF_CHANGED: { 1084 case chrome::NOTIFICATION_PREF_CHANGED: {
1108 std::string* pref_name_in = content::Details<std::string>(details).ptr(); 1085 std::string* pref_name_in = content::Details<std::string>(details).ptr();
1109 DCHECK(pref_name_in); 1086 DCHECK(pref_name_in);
1110 1087
1111 if (*pref_name_in == prefs::kEditBookmarksEnabled) { 1088 if (*pref_name_in == prefs::kEditBookmarksEnabled)
1112 UpdateStarIcon(); 1089 UpdateStarIcon();
1113 UpdateChromeToMobileIcon(); 1090 else
1114 } else {
1115 NOTREACHED(); 1091 NOTREACHED();
1116 }
1117 break; 1092 break;
1118 } 1093 }
1119 1094
1120 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { 1095 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: {
1121 if (theme_service_->UsingNativeTheme()) { 1096 if (theme_service_->UsingNativeTheme()) {
1122 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL); 1097 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL);
1123 1098
1124 GdkColor border_color = theme_service_->GetGdkColor( 1099 GdkColor border_color = theme_service_->GetGdkColor(
1125 ThemeService::COLOR_FRAME); 1100 ThemeService::COLOR_FRAME);
1126 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color); 1101 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 kBottomMargin + kBorderThickness, 1136 kBottomMargin + kBorderThickness,
1162 top_bottom, top_bottom); 1137 top_bottom, top_bottom);
1163 gtk_alignment_set_padding(GTK_ALIGNMENT(tab_to_search_alignment_), 1138 gtk_alignment_set_padding(GTK_ALIGNMENT(tab_to_search_alignment_),
1164 1, 1, 0, 0); 1139 1, 1, 0, 0);
1165 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_), 1140 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_),
1166 1, 1, 0, 0); 1141 1, 1, 0, 0);
1167 } 1142 }
1168 1143
1169 UpdateZoomIcon(); 1144 UpdateZoomIcon();
1170 UpdateStarIcon(); 1145 UpdateStarIcon();
1171 UpdateChromeToMobileIcon();
1172 UpdateSiteTypeArea(); 1146 UpdateSiteTypeArea();
1173 UpdateContentSettingsIcons(); 1147 UpdateContentSettingsIcons();
1174 UpdateWebIntentsButton(); 1148 UpdateWebIntentsButton();
1175 break; 1149 break;
1176 } 1150 }
1177 1151
1178 default: 1152 default:
1179 NOTREACHED(); 1153 NOTREACHED();
1180 } 1154 }
1181 } 1155 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 1461
1488 gboolean LocationBarViewGtk::OnStarButtonPress(GtkWidget* widget, 1462 gboolean LocationBarViewGtk::OnStarButtonPress(GtkWidget* widget,
1489 GdkEventButton* event) { 1463 GdkEventButton* event) {
1490 if (event->button == 1) { 1464 if (event->button == 1) {
1491 chrome::ExecuteCommand(browser_, IDC_BOOKMARK_PAGE); 1465 chrome::ExecuteCommand(browser_, IDC_BOOKMARK_PAGE);
1492 return TRUE; 1466 return TRUE;
1493 } 1467 }
1494 return FALSE; 1468 return FALSE;
1495 } 1469 }
1496 1470
1497 gboolean LocationBarViewGtk::OnChromeToMobileButtonPress(
1498 GtkWidget* widget,
1499 GdkEventButton* event) {
1500 if (event->button == 1) {
1501 chrome::ExecuteCommand(browser_, IDC_CHROME_TO_MOBILE_PAGE);
1502 return TRUE;
1503 }
1504 return FALSE;
1505 }
1506
1507 void LocationBarViewGtk::ShowZoomBubble() { 1471 void LocationBarViewGtk::ShowZoomBubble() {
1508 if (!zoom_.get() || toolbar_model_->input_in_progress()) 1472 if (!zoom_.get() || toolbar_model_->input_in_progress())
1509 return; 1473 return;
1510 1474
1511 ZoomBubbleGtk::Show(zoom_.get(), GetTabContents(), true); 1475 ZoomBubbleGtk::Show(zoom_.get(), GetTabContents(), true);
1512 } 1476 }
1513 1477
1514 void LocationBarViewGtk::ShowStarBubble(const GURL& url, 1478 void LocationBarViewGtk::ShowStarBubble(const GURL& url,
1515 bool newly_bookmarked) { 1479 bool newly_bookmarked) {
1516 if (!star_.get()) 1480 if (!star_.get())
1517 return; 1481 return;
1518 1482
1519 BookmarkBubbleGtk::Show(star_.get(), browser_->profile(), url, 1483 BookmarkBubbleGtk::Show(star_.get(), browser_->profile(), url,
1520 newly_bookmarked); 1484 newly_bookmarked);
1521 } 1485 }
1522 1486
1523 void LocationBarViewGtk::ShowChromeToMobileBubble() { 1487 void LocationBarViewGtk::ShowChromeToMobileBubble() {
1524 ChromeToMobileBubbleGtk::Show(GTK_IMAGE(chrome_to_mobile_image_), browser_); 1488 // TODO(msw): Chrome to Mobile is currently disabled on GTK.
1489 // ChromeToMobileBubbleGtk::Show(GTK_WIDGET(action_box_button_->widget()),
1490 // browser_);
1525 } 1491 }
1526 1492
1527 void LocationBarViewGtk::SetStarred(bool starred) { 1493 void LocationBarViewGtk::SetStarred(bool starred) {
1528 if (starred == starred_) 1494 if (starred == starred_)
1529 return; 1495 return;
1530 1496
1531 starred_ = starred; 1497 starred_ = starred;
1532 UpdateStarIcon(); 1498 UpdateStarIcon();
1533 } 1499 }
1534 1500
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 gtk_widget_show_all(star_.get()); 1539 gtk_widget_show_all(star_.get());
1574 int id = starred_ ? IDR_STAR_LIT : IDR_STAR; 1540 int id = starred_ ? IDR_STAR_LIT : IDR_STAR;
1575 gtk_image_set_from_pixbuf( 1541 gtk_image_set_from_pixbuf(
1576 GTK_IMAGE(star_image_), 1542 GTK_IMAGE(star_image_),
1577 theme_service_->GetImageNamed(id)->ToGdkPixbuf()); 1543 theme_service_->GetImageNamed(id)->ToGdkPixbuf());
1578 } else { 1544 } else {
1579 gtk_widget_hide_all(star_.get()); 1545 gtk_widget_hide_all(star_.get());
1580 } 1546 }
1581 } 1547 }
1582 1548
1583 void LocationBarViewGtk::UpdateChromeToMobileIcon() {
1584 if (!chrome_to_mobile_view_.get())
1585 return;
1586
1587 Profile* profile = browser_->profile();
1588 bool enabled = !toolbar_model_->input_in_progress() &&
1589 ChromeToMobileServiceFactory::GetForProfile(profile)->HasMobiles();
1590 gtk_widget_set_visible(chrome_to_mobile_view_.get(), enabled);
1591 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled);
1592 }
1593
1594 bool LocationBarViewGtk::ShouldOnlyShowLocation() { 1549 bool LocationBarViewGtk::ShouldOnlyShowLocation() {
1595 return !browser_->is_type_tabbed(); 1550 return !browser_->is_type_tabbed();
1596 } 1551 }
1597 1552
1598 void LocationBarViewGtk::AdjustChildrenVisibility() { 1553 void LocationBarViewGtk::AdjustChildrenVisibility() {
1599 int text_width = location_entry_->TextWidth(); 1554 int text_width = location_entry_->TextWidth();
1600 int available_width = entry_box_width_ - text_width - kInnerPadding; 1555 int available_width = entry_box_width_ - text_width - kInnerPadding;
1601 1556
1602 // Only one of |tab_to_search_alignment_| and |tab_to_search_hint_| can be 1557 // Only one of |tab_to_search_alignment_| and |tab_to_search_hint_| can be
1603 // visible at the same time. 1558 // visible at the same time.
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1928 } 1883 }
1929 1884
1930 void LocationBarViewGtk::PageActionViewGtk::Observe( 1885 void LocationBarViewGtk::PageActionViewGtk::Observe(
1931 int type, 1886 int type,
1932 const content::NotificationSource& source, 1887 const content::NotificationSource& source,
1933 const content::NotificationDetails& details) { 1888 const content::NotificationDetails& details) {
1934 DCHECK_EQ(type, chrome::NOTIFICATION_WINDOW_CLOSED); 1889 DCHECK_EQ(type, chrome::NOTIFICATION_WINDOW_CLOSED);
1935 DisconnectPageActionAccelerator(); 1890 DisconnectPageActionAccelerator();
1936 } 1891 }
1937 1892
1938 void LocationBarViewGtk::EnabledStateChangedForCommand(int id, bool enabled) {
1939 DCHECK_EQ(id, IDC_CHROME_TO_MOBILE_PAGE);
1940 if (enabled != gtk_widget_get_visible(chrome_to_mobile_view_.get()))
1941 UpdateChromeToMobileIcon();
1942 }
1943
1944 void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() { 1893 void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() {
1945 const ExtensionSet* extensions = owner_->browser()->profile()-> 1894 const ExtensionSet* extensions = owner_->browser()->profile()->
1946 GetExtensionService()->extensions(); 1895 GetExtensionService()->extensions();
1947 const Extension* extension = 1896 const Extension* extension =
1948 extensions->GetByID(page_action_->extension_id()); 1897 extensions->GetByID(page_action_->extension_id());
1949 window_ = owner_->browser()->window()->GetNativeWindow(); 1898 window_ = owner_->browser()->window()->GetNativeWindow();
1950 1899
1951 extensions::CommandService* command_service = 1900 extensions::CommandService* command_service =
1952 extensions::CommandServiceFactory::GetForProfile( 1901 extensions::CommandServiceFactory::GetForProfile(
1953 owner_->browser()->profile()); 1902 owner_->browser()->profile());
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
2134 } 2083 }
2135 2084
2136 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( 2085 void LocationBarViewGtk::PageActionViewGtk::InspectPopup(
2137 ExtensionAction* action) { 2086 ExtensionAction* action) {
2138 ExtensionPopupGtk::Show( 2087 ExtensionPopupGtk::Show(
2139 action->GetPopupUrl(current_tab_id_), 2088 action->GetPopupUrl(current_tab_id_),
2140 owner_->browser_, 2089 owner_->browser_,
2141 event_box_.get(), 2090 event_box_.get(),
2142 ExtensionPopupGtk::SHOW_AND_INSPECT); 2091 ExtensionPopupGtk::SHOW_AND_INSPECT);
2143 } 2092 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/location_bar_view_gtk.h ('k') | chrome/browser/ui/gtk/view_id_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698