Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 | 213 |
| 214 // Make sure children with layers are clipped. See http://crbug.com/589497 | 214 // Make sure children with layers are clipped. See http://crbug.com/589497 |
| 215 SetPaintToLayer(true); | 215 SetPaintToLayer(true); |
| 216 layer()->SetFillsBoundsOpaquely(false); | 216 layer()->SetFillsBoundsOpaquely(false); |
| 217 layer()->SetMasksToBounds(true); | 217 layer()->SetMasksToBounds(true); |
| 218 | 218 |
| 219 // Determine the main font. | 219 // Determine the main font. |
| 220 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList( | 220 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList( |
| 221 ResourceBundle::BaseFont); | 221 ResourceBundle::BaseFont); |
| 222 const int current_font_size = font_list.GetFontSize(); | 222 const int current_font_size = font_list.GetFontSize(); |
| 223 const int desired_font_size = GetLayoutConstant(OMNIBOX_FONT_PIXEL_SIZE); | 223 const int kDesiredFontSize = 14; |
|
Peter Kasting
2016/12/08 20:57:49
Nit: constexpr
Evan Stade
2016/12/13 01:31:18
Done.
| |
| 224 if (current_font_size != desired_font_size) { | 224 if (current_font_size != kDesiredFontSize) { |
| 225 font_list = | 225 font_list = |
| 226 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size); | 226 font_list.DeriveWithSizeDelta(kDesiredFontSize - current_font_size); |
| 227 } | 227 } |
| 228 // Shrink large fonts to make them fit. | 228 // Shrink large fonts to make them fit. |
| 229 // TODO(pkasting): Stretch the location bar instead in this case. | 229 // TODO(pkasting): Stretch the location bar instead in this case. |
| 230 const int vertical_padding = GetTotalVerticalPadding(); | 230 const int vertical_padding = GetTotalVerticalPadding(); |
| 231 const int location_height = | 231 const int location_height = |
| 232 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); | 232 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); |
| 233 font_list = font_list.DeriveWithHeightUpperBound(location_height); | 233 font_list = font_list.DeriveWithHeightUpperBound(location_height); |
| 234 | 234 |
| 235 // Determine the font for use inside the bubbles. | 235 // Determine the font for use inside the bubbles. |
| 236 const int bubble_padding = | 236 const int bubble_padding = |
| 237 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + | 237 kBubbleVerticalPadding + |
| 238 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); | 238 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); |
| 239 const int bubble_height = location_height - (bubble_padding * 2); | 239 const int bubble_height = location_height - (bubble_padding * 2); |
| 240 | 240 |
| 241 const SkColor background_color = GetColor(BACKGROUND); | 241 const SkColor background_color = GetColor(BACKGROUND); |
| 242 location_icon_view_ = new LocationIconView(font_list, this); | 242 location_icon_view_ = new LocationIconView(font_list, this); |
| 243 location_icon_view_->set_drag_controller(this); | 243 location_icon_view_->set_drag_controller(this); |
| 244 AddChildView(location_icon_view_); | 244 AddChildView(location_icon_view_); |
| 245 | 245 |
| 246 // Initialize the Omnibox view. | 246 // Initialize the Omnibox view. |
| 247 omnibox_view_ = new OmniboxViewViews( | 247 omnibox_view_ = new OmniboxViewViews( |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 | 483 |
| 484 gfx::Size LocationBarView::GetPreferredSize() const { | 484 gfx::Size LocationBarView::GetPreferredSize() const { |
| 485 // Compute minimum height. | 485 // Compute minimum height. |
| 486 gfx::Size min_size(0, GetLayoutConstant(LOCATION_BAR_HEIGHT)); | 486 gfx::Size min_size(0, GetLayoutConstant(LOCATION_BAR_HEIGHT)); |
| 487 | 487 |
| 488 if (!IsInitialized()) | 488 if (!IsInitialized()) |
| 489 return min_size; | 489 return min_size; |
| 490 | 490 |
| 491 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); | 491 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); |
| 492 | 492 |
| 493 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | |
| 494 | |
| 495 // Compute width of omnibox-leading content. | 493 // Compute width of omnibox-leading content. |
| 496 const int edge_thickness = GetHorizontalEdgeThickness(); | 494 const int edge_thickness = GetHorizontalEdgeThickness(); |
| 497 int leading_width = edge_thickness; | 495 int leading_width = edge_thickness; |
| 498 if (ShouldShowKeywordBubble()) { | 496 if (ShouldShowKeywordBubble()) { |
| 499 // The selected keyword view can collapse completely. | 497 // The selected keyword view can collapse completely. |
| 500 } else if (ShouldShowSecurityChip()) { | 498 } else if (ShouldShowSecurityChip()) { |
| 501 base::string16 security_text = GetSecurityText(); | 499 base::string16 security_text = GetSecurityText(); |
| 502 leading_width += | 500 leading_width += |
| 503 location_icon_view_->GetMinimumSizeForLabelText(security_text).width(); | 501 location_icon_view_->GetMinimumSizeForLabelText(security_text).width(); |
| 504 } else { | 502 } else { |
| 505 leading_width += padding + location_icon_view_->GetMinimumSize().width(); | 503 leading_width += |
| 504 kHorizontalPadding + location_icon_view_->GetMinimumSize().width(); | |
| 506 } | 505 } |
| 507 | 506 |
| 508 // Compute width of omnibox-trailing content. | 507 // Compute width of omnibox-trailing content. |
| 509 int trailing_width = edge_thickness; | 508 int trailing_width = edge_thickness; |
| 510 trailing_width += IncrementalMinimumWidth(star_view_) + | 509 trailing_width += IncrementalMinimumWidth(star_view_) + |
| 511 IncrementalMinimumWidth(translate_icon_view_) + | 510 IncrementalMinimumWidth(translate_icon_view_) + |
| 512 IncrementalMinimumWidth(open_pdf_in_reader_view_) + | 511 IncrementalMinimumWidth(open_pdf_in_reader_view_) + |
| 513 IncrementalMinimumWidth(save_credit_card_icon_view_) + | 512 IncrementalMinimumWidth(save_credit_card_icon_view_) + |
| 514 IncrementalMinimumWidth(manage_passwords_icon_view_) + | 513 IncrementalMinimumWidth(manage_passwords_icon_view_) + |
| 515 IncrementalMinimumWidth(zoom_view_); | 514 IncrementalMinimumWidth(zoom_view_); |
| 516 for (const auto& action_view : page_action_views_) | 515 for (const auto& action_view : page_action_views_) |
| 517 trailing_width += IncrementalMinimumWidth(action_view.get()); | 516 trailing_width += IncrementalMinimumWidth(action_view.get()); |
| 518 for (auto i = content_setting_views_.begin(); | 517 for (auto i = content_setting_views_.begin(); |
| 519 i != content_setting_views_.end(); ++i) { | 518 i != content_setting_views_.end(); ++i) { |
| 520 trailing_width += IncrementalMinimumWidth((*i)); | 519 trailing_width += IncrementalMinimumWidth((*i)); |
| 521 } | 520 } |
| 522 | 521 |
| 523 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + | 522 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + |
| 524 2 * padding - omnibox_view_->GetInsets().width() + | 523 2 * kHorizontalPadding - |
| 525 trailing_width); | 524 omnibox_view_->GetInsets().width() + trailing_width); |
| 526 return min_size; | 525 return min_size; |
| 527 } | 526 } |
| 528 | 527 |
| 529 void LocationBarView::Layout() { | 528 void LocationBarView::Layout() { |
| 530 if (!IsInitialized()) | 529 if (!IsInitialized()) |
| 531 return; | 530 return; |
| 532 | 531 |
| 533 selected_keyword_view_->SetVisible(false); | 532 selected_keyword_view_->SetVisible(false); |
| 534 location_icon_view_->SetVisible(false); | 533 location_icon_view_->SetVisible(false); |
| 535 keyword_hint_view_->SetVisible(false); | 534 keyword_hint_view_->SetVisible(false); |
| 536 | 535 |
| 537 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 536 const int item_padding = kHorizontalPadding; |
|
Peter Kasting
2016/12/08 20:57:49
Nit: Use directly below? Or make constexpr
Evan Stade
2016/12/13 01:31:18
Done.
| |
| 538 const int edge_thickness = GetHorizontalEdgeThickness(); | 537 const int edge_thickness = GetHorizontalEdgeThickness(); |
| 539 | 538 |
| 540 LocationBarLayout leading_decorations( | 539 LocationBarLayout leading_decorations( |
| 541 LocationBarLayout::LEFT_EDGE, item_padding, | 540 LocationBarLayout::LEFT_EDGE, item_padding, |
| 542 item_padding - omnibox_view_->GetInsets().left()); | 541 item_padding - omnibox_view_->GetInsets().left()); |
| 543 LocationBarLayout trailing_decorations( | 542 LocationBarLayout trailing_decorations( |
| 544 LocationBarLayout::RIGHT_EDGE, item_padding, | 543 LocationBarLayout::RIGHT_EDGE, item_padding, |
| 545 item_padding - omnibox_view_->GetInsets().right()); | 544 item_padding - omnibox_view_->GetInsets().right()); |
| 546 | 545 |
| 547 const base::string16 keyword(omnibox_view_->model()->keyword()); | 546 const base::string16 keyword(omnibox_view_->model()->keyword()); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 } | 720 } |
| 722 | 721 |
| 723 WebContents* LocationBarView::GetWebContents() { | 722 WebContents* LocationBarView::GetWebContents() { |
| 724 return delegate_->GetWebContents(); | 723 return delegate_->GetWebContents(); |
| 725 } | 724 } |
| 726 | 725 |
| 727 //////////////////////////////////////////////////////////////////////////////// | 726 //////////////////////////////////////////////////////////////////////////////// |
| 728 // LocationBarView, private: | 727 // LocationBarView, private: |
| 729 | 728 |
| 730 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { | 729 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { |
| 731 return view->visible() ? | 730 return view->visible() ? (kHorizontalPadding + view->GetMinimumSize().width()) |
| 732 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + | 731 : 0; |
| 733 view->GetMinimumSize().width()) : 0; | |
| 734 } | 732 } |
| 735 | 733 |
| 736 int LocationBarView::GetHorizontalEdgeThickness() const { | 734 int LocationBarView::GetHorizontalEdgeThickness() const { |
| 737 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); | 735 return is_popup_mode_ |
| 736 ? 0 | |
| 737 : BackgroundWith1PxBorder::kLocationBarBorderThicknessDip; | |
| 738 } | 738 } |
| 739 | 739 |
| 740 int LocationBarView::GetTotalVerticalPadding() const { | 740 int LocationBarView::GetTotalVerticalPadding() const { |
| 741 return GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) + | 741 const int kInteriorPadding = 1; |
|
Peter Kasting
2016/12/08 20:57:49
Nit: constexpr
Evan Stade
2016/12/13 01:31:18
Done.
| |
| 742 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); | 742 return BackgroundWith1PxBorder::kLocationBarBorderThicknessDip + |
| 743 kInteriorPadding; | |
| 743 } | 744 } |
| 744 | 745 |
| 745 void LocationBarView::RefreshLocationIcon() { | 746 void LocationBarView::RefreshLocationIcon() { |
| 746 // |omnibox_view_| may not be ready yet if Init() has not been called. The | 747 // |omnibox_view_| may not be ready yet if Init() has not been called. The |
| 747 // icon will be set soon by OnChanged(). | 748 // icon will be set soon by OnChanged(). |
| 748 if (!omnibox_view_) | 749 if (!omnibox_view_) |
| 749 return; | 750 return; |
| 750 | 751 |
| 751 security_state::SecurityLevel security_level = | 752 security_state::SecurityLevel security_level = |
| 752 GetToolbarModel()->GetSecurityLevel(false); | 753 GetToolbarModel()->GetSecurityLevel(false); |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1175 canvas->DrawRoundRect(focus_rect, | 1176 canvas->DrawRoundRect(focus_rect, |
| 1176 BackgroundWith1PxBorder::kCornerRadius + 0.5f, paint); | 1177 BackgroundWith1PxBorder::kCornerRadius + 0.5f, paint); |
| 1177 } | 1178 } |
| 1178 if (!is_popup_mode_) | 1179 if (!is_popup_mode_) |
| 1179 return; // The background and border are painted by our Background. | 1180 return; // The background and border are painted by our Background. |
| 1180 | 1181 |
| 1181 // Fill the location bar background color behind the border. Parts of the | 1182 // Fill the location bar background color behind the border. Parts of the |
| 1182 // border images are meant to rest atop the toolbar background and parts atop | 1183 // border images are meant to rest atop the toolbar background and parts atop |
| 1183 // the omnibox background, so we can't just blindly fill our entire bounds. | 1184 // the omnibox background, so we can't just blindly fill our entire bounds. |
| 1184 gfx::Rect bounds(GetContentsBounds()); | 1185 gfx::Rect bounds(GetContentsBounds()); |
| 1185 bounds.Inset( | 1186 bounds.Inset(GetHorizontalEdgeThickness(), |
| 1186 GetHorizontalEdgeThickness(), | 1187 is_popup_mode_ |
| 1187 is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS)); | 1188 ? 0 |
| 1189 : BackgroundWith1PxBorder::kLocationBarBorderThicknessDip); | |
| 1188 SkColor background_color(GetColor(BACKGROUND)); | 1190 SkColor background_color(GetColor(BACKGROUND)); |
| 1189 canvas->FillRect(bounds, background_color); | 1191 canvas->FillRect(bounds, background_color); |
| 1190 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord()); | 1192 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord()); |
| 1191 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false); | 1193 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false); |
| 1192 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true); | 1194 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true); |
| 1193 } | 1195 } |
| 1194 | 1196 |
| 1195 //////////////////////////////////////////////////////////////////////////////// | 1197 //////////////////////////////////////////////////////////////////////////////// |
| 1196 // LocationBarView, private views::DragController implementation: | 1198 // LocationBarView, private views::DragController implementation: |
| 1197 | 1199 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1261 // LocationBarView, private TemplateURLServiceObserver implementation: | 1263 // LocationBarView, private TemplateURLServiceObserver implementation: |
| 1262 | 1264 |
| 1263 void LocationBarView::OnTemplateURLServiceChanged() { | 1265 void LocationBarView::OnTemplateURLServiceChanged() { |
| 1264 template_url_service_->RemoveObserver(this); | 1266 template_url_service_->RemoveObserver(this); |
| 1265 template_url_service_ = nullptr; | 1267 template_url_service_ = nullptr; |
| 1266 // If the browser is no longer active, let's not show the info bubble, as this | 1268 // If the browser is no longer active, let's not show the info bubble, as this |
| 1267 // would make the browser the active window again. | 1269 // would make the browser the active window again. |
| 1268 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1270 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
| 1269 ShowFirstRunBubble(); | 1271 ShowFirstRunBubble(); |
| 1270 } | 1272 } |
| OLD | NEW |