OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 const int kInnerPadding = 2; | 88 const int kInnerPadding = 2; |
89 | 89 |
90 // Padding between the right of the star and the edge of the URL entry. | 90 // Padding between the right of the star and the edge of the URL entry. |
91 const int kStarRightPadding = 2; | 91 const int kStarRightPadding = 2; |
92 | 92 |
93 // Colors used to draw the EV certificate rounded bubble. | 93 // Colors used to draw the EV certificate rounded bubble. |
94 const GdkColor kEvSecureTextColor = GDK_COLOR_RGB(0x07, 0x95, 0x00); | 94 const GdkColor kEvSecureTextColor = GDK_COLOR_RGB(0x07, 0x95, 0x00); |
95 const GdkColor kEvSecureBackgroundColor = GDK_COLOR_RGB(0xef, 0xfc, 0xef); | 95 const GdkColor kEvSecureBackgroundColor = GDK_COLOR_RGB(0xef, 0xfc, 0xef); |
96 const GdkColor kEvSecureBorderColor = GDK_COLOR_RGB(0x90, 0xc3, 0x90); | 96 const GdkColor kEvSecureBorderColor = GDK_COLOR_RGB(0x90, 0xc3, 0x90); |
97 | 97 |
| 98 // Colors used to draw the account bubble. |
| 99 const GdkColor kAccountTextColor = GDK_COLOR_RGB(0x14, 0x52, 0xa1); |
| 100 const GdkColor kAccountBackgroundColor = GDK_COLOR_RGB(0xe8, 0xf1, 0xfc); |
| 101 const GdkColor kAccountBorderColor = GDK_COLOR_RGB(0x8c, 0xb2, 0xde); |
| 102 |
98 // Colors used to draw the Tab to Search rounded bubble. | 103 // Colors used to draw the Tab to Search rounded bubble. |
99 const GdkColor kKeywordBackgroundColor = GDK_COLOR_RGB(0xf0, 0xf4, 0xfa); | 104 const GdkColor kKeywordBackgroundColor = GDK_COLOR_RGB(0xf0, 0xf4, 0xfa); |
100 const GdkColor kKeywordBorderColor = GDK_COLOR_RGB(0xcb, 0xde, 0xf7); | 105 const GdkColor kKeywordBorderColor = GDK_COLOR_RGB(0xcb, 0xde, 0xf7); |
101 | 106 |
102 // Use weak gray for showing search and keyword hint text. | 107 // Use weak gray for showing search and keyword hint text. |
103 const GdkColor kHintTextColor = GDK_COLOR_RGB(0x75, 0x75, 0x75); | 108 const GdkColor kHintTextColor = GDK_COLOR_RGB(0x75, 0x75, 0x75); |
104 | 109 |
105 // Size of the rounding of the "Search site for:" box. | 110 // Size of the rounding of the "Search site for:" box. |
106 const int kCornerSize = 3; | 111 const int kCornerSize = 3; |
107 | 112 |
(...skipping 15 matching lines...) Expand all Loading... |
123 | 128 |
124 LocationBarViewGtk::LocationBarViewGtk(Browser* browser) | 129 LocationBarViewGtk::LocationBarViewGtk(Browser* browser) |
125 : star_image_(NULL), | 130 : star_image_(NULL), |
126 starred_(false), | 131 starred_(false), |
127 site_type_alignment_(NULL), | 132 site_type_alignment_(NULL), |
128 site_type_event_box_(NULL), | 133 site_type_event_box_(NULL), |
129 location_icon_image_(NULL), | 134 location_icon_image_(NULL), |
130 drag_icon_(NULL), | 135 drag_icon_(NULL), |
131 enable_location_drag_(false), | 136 enable_location_drag_(false), |
132 security_info_label_(NULL), | 137 security_info_label_(NULL), |
| 138 account_label_(NULL), |
133 tab_to_search_box_(NULL), | 139 tab_to_search_box_(NULL), |
134 tab_to_search_full_label_(NULL), | 140 tab_to_search_full_label_(NULL), |
135 tab_to_search_partial_label_(NULL), | 141 tab_to_search_partial_label_(NULL), |
136 tab_to_search_hint_(NULL), | 142 tab_to_search_hint_(NULL), |
137 tab_to_search_hint_leading_label_(NULL), | 143 tab_to_search_hint_leading_label_(NULL), |
138 tab_to_search_hint_icon_(NULL), | 144 tab_to_search_hint_icon_(NULL), |
139 tab_to_search_hint_trailing_label_(NULL), | 145 tab_to_search_hint_trailing_label_(NULL), |
140 profile_(NULL), | 146 profile_(NULL), |
141 command_updater_(browser->command_updater()), | 147 command_updater_(browser->command_updater()), |
142 toolbar_model_(browser->toolbar_model()), | 148 toolbar_model_(browser->toolbar_model()), |
143 browser_(browser), | 149 browser_(browser), |
144 disposition_(CURRENT_TAB), | 150 disposition_(CURRENT_TAB), |
145 transition_(PageTransition::TYPED), | 151 transition_(PageTransition::TYPED), |
146 first_run_bubble_(this), | 152 first_run_bubble_(this), |
147 popup_window_mode_(false), | 153 popup_window_mode_(false), |
148 theme_provider_(NULL), | 154 theme_provider_(NULL), |
149 hbox_width_(0), | 155 hbox_width_(0), |
150 entry_box_width_(0), | 156 entry_box_width_(0), |
151 show_selected_keyword_(false), | 157 show_selected_keyword_(false), |
152 show_keyword_hint_(false), | 158 show_keyword_hint_(false), |
153 update_instant_(true) { | 159 update_instant_(true) { |
154 } | 160 } |
155 | 161 |
156 LocationBarViewGtk::~LocationBarViewGtk() { | 162 LocationBarViewGtk::~LocationBarViewGtk() { |
157 // All of our widgets should have be children of / owned by the alignment. | 163 // All of our widgets should have be children of / owned by the alignment. |
158 star_.Destroy(); | 164 star_.Destroy(); |
159 hbox_.Destroy(); | 165 hbox_.Destroy(); |
| 166 account_alignment_.Destroy(); |
| 167 account_event_box_.Destroy(); |
| 168 account_icon_image_.Destroy(); |
160 content_setting_hbox_.Destroy(); | 169 content_setting_hbox_.Destroy(); |
161 page_action_hbox_.Destroy(); | 170 page_action_hbox_.Destroy(); |
162 } | 171 } |
163 | 172 |
164 void LocationBarViewGtk::Init(bool popup_window_mode) { | 173 void LocationBarViewGtk::Init(bool popup_window_mode) { |
165 popup_window_mode_ = popup_window_mode; | 174 popup_window_mode_ = popup_window_mode; |
166 | 175 |
167 // Create the widget first, so we can pass it to the AutocompleteEditViewGtk. | 176 // Create the widget first, so we can pass it to the AutocompleteEditViewGtk. |
168 hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); | 177 hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); |
169 gtk_container_set_border_width(GTK_CONTAINER(hbox_.get()), kHboxBorder); | 178 gtk_container_set_border_width(GTK_CONTAINER(hbox_.get()), kHboxBorder); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 gtk_box_pack_end(GTK_BOX(content_setting_hbox_.get()), | 292 gtk_box_pack_end(GTK_BOX(content_setting_hbox_.get()), |
284 content_setting_view->widget(), FALSE, FALSE, 0); | 293 content_setting_view->widget(), FALSE, FALSE, 0); |
285 } | 294 } |
286 | 295 |
287 page_action_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); | 296 page_action_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); |
288 gtk_widget_set_name(page_action_hbox_.get(), | 297 gtk_widget_set_name(page_action_hbox_.get(), |
289 "chrome-page-action-hbox"); | 298 "chrome-page-action-hbox"); |
290 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), | 299 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), |
291 FALSE, FALSE, 0); | 300 FALSE, FALSE, 0); |
292 | 301 |
| 302 // Create the account area view. |
| 303 BuildAccountArea(); |
| 304 |
293 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s | 305 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s |
294 // size-allocate so we can do proper resizing and eliding on | 306 // size-allocate so we can do proper resizing and eliding on |
295 // |security_info_label_|. | 307 // |security_info_label_|. |
296 g_signal_connect(hbox_.get(), "size-allocate", | 308 g_signal_connect(hbox_.get(), "size-allocate", |
297 G_CALLBACK(&OnHboxSizeAllocateThunk), this); | 309 G_CALLBACK(&OnHboxSizeAllocateThunk), this); |
298 | 310 |
299 registrar_.Add(this, | 311 registrar_.Add(this, |
300 NotificationType::BROWSER_THEME_CHANGED, | 312 NotificationType::BROWSER_THEME_CHANGED, |
301 NotificationService::AllSources()); | 313 NotificationService::AllSources()); |
302 theme_provider_ = GtkThemeProvider::GetFrom(profile_); | 314 theme_provider_ = GtkThemeProvider::GetFrom(profile_); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 } | 381 } |
370 | 382 |
371 gtk_drag_source_set(site_type_event_box_, GDK_BUTTON1_MASK, | 383 gtk_drag_source_set(site_type_event_box_, GDK_BUTTON1_MASK, |
372 NULL, 0, GDK_ACTION_COPY); | 384 NULL, 0, GDK_ACTION_COPY); |
373 ui::SetSourceTargetListFromCodeMask(site_type_event_box_, | 385 ui::SetSourceTargetListFromCodeMask(site_type_event_box_, |
374 ui::TEXT_PLAIN | | 386 ui::TEXT_PLAIN | |
375 ui::TEXT_URI_LIST | | 387 ui::TEXT_URI_LIST | |
376 ui::CHROME_NAMED_URL); | 388 ui::CHROME_NAMED_URL); |
377 } | 389 } |
378 | 390 |
| 391 void LocationBarViewGtk::BuildAccountArea() { |
| 392 account_icon_image_.Own(gtk_image_new()); |
| 393 gtk_widget_set_name(account_icon_image_.get(), "chrome-account-icon"); |
| 394 |
| 395 GtkWidget* icon_alignment = gtk_alignment_new(0, 0, 1, 1); |
| 396 gtk_alignment_set_padding(GTK_ALIGNMENT(icon_alignment), 0, 0, 2, 0); |
| 397 gtk_container_add(GTK_CONTAINER(icon_alignment), account_icon_image_.get()); |
| 398 gtk_widget_show_all(icon_alignment); |
| 399 |
| 400 account_label_ = gtk_label_new(NULL); |
| 401 gtk_label_set_ellipsize(GTK_LABEL(account_label_), |
| 402 PANGO_ELLIPSIZE_MIDDLE); |
| 403 gtk_widget_modify_fg(GTK_WIDGET(account_label_), GTK_STATE_NORMAL, |
| 404 &kAccountTextColor); |
| 405 gtk_widget_set_name(account_label_, |
| 406 "chrome-location-bar-account-label"); |
| 407 |
| 408 GtkWidget* account_hbox = gtk_hbox_new(FALSE, 0); |
| 409 gtk_box_pack_start(GTK_BOX(account_hbox), icon_alignment, |
| 410 FALSE, FALSE, 0); |
| 411 |
| 412 GtkWidget* label_alignment = gtk_alignment_new(0, 0, 1, 1); |
| 413 gtk_alignment_set_padding(GTK_ALIGNMENT(label_alignment), 0, 0, 0, 4); |
| 414 gtk_container_add(GTK_CONTAINER(label_alignment), account_label_); |
| 415 gtk_box_pack_start(GTK_BOX(account_hbox), label_alignment, FALSE, FALSE, 1); |
| 416 |
| 417 account_event_box_.Own(gtk_event_box_new()); |
| 418 gtk_widget_modify_bg(account_event_box_.get(), GTK_STATE_NORMAL, |
| 419 &kAccountBackgroundColor); |
| 420 |
| 421 // Make the event box not visible so it does not paint a background. |
| 422 gtk_event_box_set_visible_window(GTK_EVENT_BOX(account_event_box_.get()), |
| 423 FALSE); |
| 424 gtk_widget_set_name(account_event_box_.get(), |
| 425 "chrome-location-bar-account-eventbox"); |
| 426 gtk_container_add(GTK_CONTAINER(account_event_box_.get()), account_hbox); |
| 427 |
| 428 // Put the event box in an alignment to get the padding correct |
| 429 account_alignment_.Own(gtk_alignment_new(0, 0, 1, 1)); |
| 430 gtk_alignment_set_padding(GTK_ALIGNMENT(account_alignment_.get()), |
| 431 1, 1, 0, 2); |
| 432 gtk_container_add(GTK_CONTAINER(account_alignment_.get()), |
| 433 account_event_box_.get()); |
| 434 |
| 435 gtk_box_pack_end(GTK_BOX(hbox_.get()), account_alignment_.get(), |
| 436 FALSE, FALSE, 0); |
| 437 } |
| 438 |
379 void LocationBarViewGtk::SetProfile(Profile* profile) { | 439 void LocationBarViewGtk::SetProfile(Profile* profile) { |
380 profile_ = profile; | 440 profile_ = profile; |
381 } | 441 } |
382 | 442 |
383 TabContents* LocationBarViewGtk::GetTabContents() const { | 443 TabContents* LocationBarViewGtk::GetTabContents() const { |
384 return browser_->GetSelectedTabContents(); | 444 return browser_->GetSelectedTabContents(); |
385 } | 445 } |
386 | 446 |
387 void LocationBarViewGtk::SetPreviewEnabledPageAction( | 447 void LocationBarViewGtk::SetPreviewEnabledPageAction( |
388 ExtensionAction *page_action, | 448 ExtensionAction *page_action, |
(...skipping 27 matching lines...) Expand all Loading... |
416 void LocationBarViewGtk::Update(const TabContents* contents) { | 476 void LocationBarViewGtk::Update(const TabContents* contents) { |
417 bool star_enabled = star_.get() && !toolbar_model_->input_in_progress(); | 477 bool star_enabled = star_.get() && !toolbar_model_->input_in_progress(); |
418 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); | 478 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); |
419 if (star_.get()) { | 479 if (star_.get()) { |
420 if (star_enabled) | 480 if (star_enabled) |
421 gtk_widget_show_all(star_.get()); | 481 gtk_widget_show_all(star_.get()); |
422 else | 482 else |
423 gtk_widget_hide_all(star_.get()); | 483 gtk_widget_hide_all(star_.get()); |
424 } | 484 } |
425 UpdateSiteTypeArea(); | 485 UpdateSiteTypeArea(); |
| 486 UpdateAccountArea(); |
426 UpdateContentSettingsIcons(); | 487 UpdateContentSettingsIcons(); |
427 UpdatePageActions(); | 488 UpdatePageActions(); |
428 location_entry_->Update(contents); | 489 location_entry_->Update(contents); |
429 // The security level (background color) could have changed, etc. | 490 // The security level (background color) could have changed, etc. |
430 if (theme_provider_->UseGtkTheme()) { | 491 if (theme_provider_->UseGtkTheme()) { |
431 // In GTK mode, we need our parent to redraw, as it draws the text entry | 492 // In GTK mode, we need our parent to redraw, as it draws the text entry |
432 // border. | 493 // border. |
433 gtk_widget_queue_draw(widget()->parent); | 494 gtk_widget_queue_draw(widget()->parent); |
434 } else { | 495 } else { |
435 gtk_widget_queue_draw(widget()); | 496 gtk_widget_queue_draw(widget()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 } | 574 } |
514 | 575 |
515 if (browser_->instant() && !location_entry_->model()->popup_model()->IsOpen()) | 576 if (browser_->instant() && !location_entry_->model()->popup_model()->IsOpen()) |
516 browser_->instant()->DestroyPreviewContents(); | 577 browser_->instant()->DestroyPreviewContents(); |
517 | 578 |
518 update_instant_ = true; | 579 update_instant_ = true; |
519 } | 580 } |
520 | 581 |
521 void LocationBarViewGtk::OnChanged() { | 582 void LocationBarViewGtk::OnChanged() { |
522 UpdateSiteTypeArea(); | 583 UpdateSiteTypeArea(); |
| 584 UpdateAccountArea(); |
523 | 585 |
524 const string16 keyword(location_entry_->model()->keyword()); | 586 const string16 keyword(location_entry_->model()->keyword()); |
525 const bool is_keyword_hint = location_entry_->model()->is_keyword_hint(); | 587 const bool is_keyword_hint = location_entry_->model()->is_keyword_hint(); |
526 show_selected_keyword_ = !keyword.empty() && !is_keyword_hint; | 588 show_selected_keyword_ = !keyword.empty() && !is_keyword_hint; |
527 show_keyword_hint_ = !keyword.empty() && is_keyword_hint; | 589 show_keyword_hint_ = !keyword.empty() && is_keyword_hint; |
528 | 590 |
529 if (show_selected_keyword_) | 591 if (show_selected_keyword_) |
530 SetKeywordLabel(keyword); | 592 SetKeywordLabel(keyword); |
531 | 593 |
532 if (show_keyword_hint_) | 594 if (show_keyword_hint_) |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 GdkColor border_color = theme_provider_->GetGdkColor( | 876 GdkColor border_color = theme_provider_->GetGdkColor( |
815 BrowserThemeProvider::COLOR_FRAME); | 877 BrowserThemeProvider::COLOR_FRAME); |
816 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color); | 878 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color); |
817 | 879 |
818 gtk_util::SetLabelColor(tab_to_search_full_label_, NULL); | 880 gtk_util::SetLabelColor(tab_to_search_full_label_, NULL); |
819 gtk_util::SetLabelColor(tab_to_search_partial_label_, NULL); | 881 gtk_util::SetLabelColor(tab_to_search_partial_label_, NULL); |
820 gtk_util::SetLabelColor(tab_to_search_hint_leading_label_, NULL); | 882 gtk_util::SetLabelColor(tab_to_search_hint_leading_label_, NULL); |
821 gtk_util::SetLabelColor(tab_to_search_hint_trailing_label_, NULL); | 883 gtk_util::SetLabelColor(tab_to_search_hint_trailing_label_, NULL); |
822 | 884 |
823 gtk_util::UndoForceFontSize(security_info_label_); | 885 gtk_util::UndoForceFontSize(security_info_label_); |
| 886 gtk_util::UndoForceFontSize(account_label_); |
824 gtk_util::UndoForceFontSize(tab_to_search_full_label_); | 887 gtk_util::UndoForceFontSize(tab_to_search_full_label_); |
825 gtk_util::UndoForceFontSize(tab_to_search_partial_label_); | 888 gtk_util::UndoForceFontSize(tab_to_search_partial_label_); |
826 gtk_util::UndoForceFontSize(tab_to_search_hint_leading_label_); | 889 gtk_util::UndoForceFontSize(tab_to_search_hint_leading_label_); |
827 gtk_util::UndoForceFontSize(tab_to_search_hint_trailing_label_); | 890 gtk_util::UndoForceFontSize(tab_to_search_hint_trailing_label_); |
828 | 891 |
829 gtk_alignment_set_padding(GTK_ALIGNMENT(location_entry_alignment_), | 892 gtk_alignment_set_padding(GTK_ALIGNMENT(location_entry_alignment_), |
830 0, 0, 0, 0); | 893 0, 0, 0, 0); |
831 } else { | 894 } else { |
832 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, | 895 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, |
833 &kKeywordBackgroundColor); | 896 &kKeywordBackgroundColor); |
834 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, | 897 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, |
835 kKeywordBorderColor); | 898 kKeywordBorderColor); |
836 | 899 |
837 gtk_util::SetLabelColor(tab_to_search_full_label_, >k_util::kGdkBlack); | 900 gtk_util::SetLabelColor(tab_to_search_full_label_, >k_util::kGdkBlack); |
838 gtk_util::SetLabelColor(tab_to_search_partial_label_, >k_util::kGdkBlack); | 901 gtk_util::SetLabelColor(tab_to_search_partial_label_, >k_util::kGdkBlack); |
839 gtk_util::SetLabelColor(tab_to_search_hint_leading_label_, | 902 gtk_util::SetLabelColor(tab_to_search_hint_leading_label_, |
840 &kHintTextColor); | 903 &kHintTextColor); |
841 gtk_util::SetLabelColor(tab_to_search_hint_trailing_label_, | 904 gtk_util::SetLabelColor(tab_to_search_hint_trailing_label_, |
842 &kHintTextColor); | 905 &kHintTextColor); |
843 | 906 |
844 // Until we switch to vector graphics, force the font size of labels. | 907 // Until we switch to vector graphics, force the font size of labels. |
845 // 12.1px = 9pt @ 96dpi | 908 // 12.1px = 9pt @ 96dpi |
846 gtk_util::ForceFontSizePixels(security_info_label_, 12.1); | 909 gtk_util::ForceFontSizePixels(security_info_label_, 12.1); |
| 910 gtk_util::ForceFontSizePixels(account_label_, 12.1); |
847 gtk_util::ForceFontSizePixels(tab_to_search_full_label_, | 911 gtk_util::ForceFontSizePixels(tab_to_search_full_label_, |
848 browser_defaults::kAutocompleteEditFontPixelSize); | 912 browser_defaults::kAutocompleteEditFontPixelSize); |
849 gtk_util::ForceFontSizePixels(tab_to_search_partial_label_, | 913 gtk_util::ForceFontSizePixels(tab_to_search_partial_label_, |
850 browser_defaults::kAutocompleteEditFontPixelSize); | 914 browser_defaults::kAutocompleteEditFontPixelSize); |
851 gtk_util::ForceFontSizePixels(tab_to_search_hint_leading_label_, | 915 gtk_util::ForceFontSizePixels(tab_to_search_hint_leading_label_, |
852 browser_defaults::kAutocompleteEditFontPixelSize); | 916 browser_defaults::kAutocompleteEditFontPixelSize); |
853 gtk_util::ForceFontSizePixels(tab_to_search_hint_trailing_label_, | 917 gtk_util::ForceFontSizePixels(tab_to_search_hint_trailing_label_, |
854 browser_defaults::kAutocompleteEditFontPixelSize); | 918 browser_defaults::kAutocompleteEditFontPixelSize); |
855 | 919 |
856 if (popup_window_mode_) { | 920 if (popup_window_mode_) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 int max_chars = static_cast<int>(static_cast<float>(text_area) / | 1030 int max_chars = static_cast<int>(static_cast<float>(text_area) / |
967 static_cast<float>(char_width) / 2.75); | 1031 static_cast<float>(char_width) / 2.75); |
968 // Don't let the label be smaller than 10 characters so that the country | 1032 // Don't let the label be smaller than 10 characters so that the country |
969 // code is always visible. | 1033 // code is always visible. |
970 gtk_label_set_max_width_chars(GTK_LABEL(security_info_label_), | 1034 gtk_label_set_max_width_chars(GTK_LABEL(security_info_label_), |
971 std::max(10, max_chars)); | 1035 std::max(10, max_chars)); |
972 | 1036 |
973 pango_font_metrics_unref(metrics); | 1037 pango_font_metrics_unref(metrics); |
974 } | 1038 } |
975 | 1039 |
| 1040 void LocationBarViewGtk::UpdateAccountArea() { |
| 1041 // The account is always visible except when the |tab_to_search_box_| is |
| 1042 // visible. |
| 1043 if (!location_entry_->model()->keyword().empty() && |
| 1044 !location_entry_->model()->is_keyword_hint()) { |
| 1045 gtk_widget_hide(account_event_box_.get()); |
| 1046 return; |
| 1047 } |
| 1048 |
| 1049 int resource_id = IDR_OMNIBOX_ACCOUNT; |
| 1050 gtk_image_set_from_pixbuf(GTK_IMAGE(account_icon_image_.get()), |
| 1051 theme_provider_->GetPixbufNamed(resource_id)); |
| 1052 |
| 1053 string16 site_account = toolbar_model_->GetSiteAccount(); |
| 1054 if (!site_account.empty()) { |
| 1055 if (!gtk_util::IsActingAsRoundedWindow(account_event_box_.get())) { |
| 1056 gtk_event_box_set_visible_window(GTK_EVENT_BOX(account_event_box_.get()), |
| 1057 TRUE); |
| 1058 gtk_util::ActAsRoundedWindow(account_event_box_.get(), |
| 1059 kAccountBorderColor, |
| 1060 kCornerSize, |
| 1061 gtk_util::ROUNDED_ALL, |
| 1062 gtk_util::BORDER_ALL); |
| 1063 } |
| 1064 |
| 1065 gtk_label_set_text(GTK_LABEL(account_label_), |
| 1066 UTF16ToUTF8(site_account).c_str()); |
| 1067 UpdateAccountLabelSize(); |
| 1068 |
| 1069 gtk_widget_set_tooltip_text( |
| 1070 GTK_WIDGET(account_event_box_.get()), |
| 1071 l10n_util::GetStringFUTF8(IDS_PAGE_INFO_TLS_USER_IDENTITY, |
| 1072 toolbar_model_->GetSiteName(), |
| 1073 site_account).c_str()); |
| 1074 |
| 1075 gtk_widget_show(GTK_WIDGET(account_event_box_.get())); |
| 1076 } else { |
| 1077 if (gtk_util::IsActingAsRoundedWindow(account_event_box_.get())) { |
| 1078 gtk_util::StopActingAsRoundedWindow(account_event_box_.get()); |
| 1079 gtk_event_box_set_visible_window(GTK_EVENT_BOX(account_event_box_.get()), |
| 1080 FALSE); |
| 1081 } |
| 1082 |
| 1083 gtk_widget_hide(GTK_WIDGET(account_event_box_.get())); |
| 1084 } |
| 1085 } |
| 1086 |
| 1087 void LocationBarViewGtk::UpdateAccountLabelSize() { |
| 1088 // TODO(sqs): duplicate of above - condense |
| 1089 // Figure out the width of the average character. |
| 1090 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(account_label_)); |
| 1091 PangoContext* context = pango_layout_get_context(layout); |
| 1092 PangoFontMetrics* metrics = pango_context_get_metrics( |
| 1093 context, |
| 1094 gtk_widget_get_style(account_label_)->font_desc, |
| 1095 pango_context_get_language(context)); |
| 1096 int char_width = |
| 1097 pango_font_metrics_get_approximate_char_width(metrics) / PANGO_SCALE; |
| 1098 |
| 1099 // The EV label should never take up more than half the hbox. We try to |
| 1100 // correct our inaccurate measurement units ("the average character width") |
| 1101 // by dividing more than an even 2. |
| 1102 int text_area = account_label_->allocation.width + |
| 1103 entry_box_->allocation.width; |
| 1104 int max_chars = static_cast<int>(static_cast<float>(text_area) / |
| 1105 static_cast<float>(char_width) / 2.75); |
| 1106 // Don't let the label be smaller than 10 characters so that the country |
| 1107 // code is always visible. |
| 1108 gtk_label_set_max_width_chars(GTK_LABEL(account_label_), |
| 1109 std::max(10, max_chars)); |
| 1110 |
| 1111 pango_font_metrics_unref(metrics); |
| 1112 } |
| 1113 |
976 void LocationBarViewGtk::SetKeywordLabel(const string16& keyword) { | 1114 void LocationBarViewGtk::SetKeywordLabel(const string16& keyword) { |
977 if (keyword.empty()) | 1115 if (keyword.empty()) |
978 return; | 1116 return; |
979 | 1117 |
980 DCHECK(profile_); | 1118 DCHECK(profile_); |
981 if (!profile_->GetTemplateURLModel()) | 1119 if (!profile_->GetTemplateURLModel()) |
982 return; | 1120 return; |
983 | 1121 |
984 bool is_extension_keyword; | 1122 bool is_extension_keyword; |
985 const string16 short_name = profile_->GetTemplateURLModel()-> | 1123 const string16 short_name = profile_->GetTemplateURLModel()-> |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 | 1684 |
1547 std::string badge_text = page_action_->GetBadgeText(tab_id); | 1685 std::string badge_text = page_action_->GetBadgeText(tab_id); |
1548 if (badge_text.empty()) | 1686 if (badge_text.empty()) |
1549 return FALSE; | 1687 return FALSE; |
1550 | 1688 |
1551 gfx::CanvasSkiaPaint canvas(event, false); | 1689 gfx::CanvasSkiaPaint canvas(event, false); |
1552 gfx::Rect bounding_rect(widget->allocation); | 1690 gfx::Rect bounding_rect(widget->allocation); |
1553 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); | 1691 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); |
1554 return FALSE; | 1692 return FALSE; |
1555 } | 1693 } |
OLD | NEW |