| 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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/command_updater.h" | 15 #include "chrome/browser/command_updater.h" |
| 16 #include "chrome/browser/defaults.h" | 16 #include "chrome/browser/defaults.h" |
| 17 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 17 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 18 #include "chrome/browser/extensions/extension_action.h" | 18 #include "chrome/browser/extensions/extension_action.h" |
| 19 #include "chrome/browser/extensions/extension_action_manager.h" | 19 #include "chrome/browser/extensions/extension_action_manager.h" |
| 20 #include "chrome/browser/extensions/extension_util.h" | 20 #include "chrome/browser/extensions/extension_util.h" |
| 21 #include "chrome/browser/extensions/location_bar_controller.h" | 21 #include "chrome/browser/extensions/location_bar_controller.h" |
| 22 #include "chrome/browser/extensions/tab_helper.h" | 22 #include "chrome/browser/extensions/tab_helper.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/search_engines/template_url_service_factory.h" | 24 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 25 #include "chrome/browser/themes/theme_properties.h" |
| 25 #include "chrome/browser/translate/chrome_translate_client.h" | 26 #include "chrome/browser/translate/chrome_translate_client.h" |
| 26 #include "chrome/browser/translate/translate_service.h" | 27 #include "chrome/browser/translate/translate_service.h" |
| 27 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" | 28 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
| 28 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_finder.h" | 30 #include "chrome/browser/ui/browser_finder.h" |
| 30 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
| 31 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 32 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 32 #include "chrome/browser/ui/layout_constants.h" | 33 #include "chrome/browser/ui/layout_constants.h" |
| 33 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 34 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 35 #include "chrome/browser/ui/views/autofill/save_card_icon_view.h" | 36 #include "chrome/browser/ui/views/autofill/save_card_icon_view.h" |
| 36 #include "chrome/browser/ui/views/browser_dialogs.h" | 37 #include "chrome/browser/ui/views/browser_dialogs.h" |
| 38 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 37 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" | 39 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
| 38 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" | 40 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
| 39 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 41 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 40 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" | 42 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" |
| 41 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 43 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 42 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" | 44 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" |
| 43 #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" |
| 44 #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" |
| 45 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 47 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
| 46 #include "chrome/browser/ui/views/location_bar/star_view.h" | 48 #include "chrome/browser/ui/views/location_bar/star_view.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (template_url_service_) | 158 if (template_url_service_) |
| 157 template_url_service_->RemoveObserver(this); | 159 template_url_service_->RemoveObserver(this); |
| 158 | 160 |
| 159 ui_zoom::ZoomEventManager::GetForBrowserContext(profile()) | 161 ui_zoom::ZoomEventManager::GetForBrowserContext(profile()) |
| 160 ->RemoveZoomEventManagerObserver(this); | 162 ->RemoveZoomEventManagerObserver(this); |
| 161 } | 163 } |
| 162 | 164 |
| 163 //////////////////////////////////////////////////////////////////////////////// | 165 //////////////////////////////////////////////////////////////////////////////// |
| 164 // LocationBarView, public: | 166 // LocationBarView, public: |
| 165 | 167 |
| 168 // static |
| 169 SkColor LocationBarView::GetBorderColor(bool incognito) { |
| 170 return color_utils::AlphaBlend( |
| 171 SkColorSetA(kBorderColor, SK_AlphaOPAQUE), |
| 172 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR, |
| 173 incognito), |
| 174 SkColorGetA(kBorderColor)); |
| 175 } |
| 176 |
| 166 void LocationBarView::Init() { | 177 void LocationBarView::Init() { |
| 167 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're | 178 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're |
| 168 // not prepared for that. | 179 // not prepared for that. |
| 169 DCHECK(GetWidget()); | 180 DCHECK(GetWidget()); |
| 170 | 181 |
| 171 if (!ui::MaterialDesignController::IsModeMaterial()) { | 182 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 172 if (is_popup_mode_) { | 183 if (is_popup_mode_) { |
| 173 const int kOmniboxPopupBorderImages[] = | 184 const int kOmniboxPopupBorderImages[] = |
| 174 IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER_AND_SHADOW); | 185 IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER_AND_SHADOW); |
| 175 border_painter_.reset( | 186 border_painter_.reset( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 186 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList( | 197 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList( |
| 187 ResourceBundle::BaseFont); | 198 ResourceBundle::BaseFont); |
| 188 const int current_font_size = font_list.GetFontSize(); | 199 const int current_font_size = font_list.GetFontSize(); |
| 189 const int desired_font_size = GetLayoutConstant(OMNIBOX_FONT_PIXEL_SIZE); | 200 const int desired_font_size = GetLayoutConstant(OMNIBOX_FONT_PIXEL_SIZE); |
| 190 if (current_font_size != desired_font_size) { | 201 if (current_font_size != desired_font_size) { |
| 191 font_list = | 202 font_list = |
| 192 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size); | 203 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size); |
| 193 } | 204 } |
| 194 // Shrink large fonts to make them fit. | 205 // Shrink large fonts to make them fit. |
| 195 // TODO(pkasting): Stretch the location bar instead in this case. | 206 // TODO(pkasting): Stretch the location bar instead in this case. |
| 196 const int location_height = GetInternalHeight(true); | 207 const int vertical_padding = GetVerticalEdgeThicknessWithPadding(false); |
| 208 const int location_height = |
| 209 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); |
| 197 font_list = font_list.DeriveWithHeightUpperBound(location_height); | 210 font_list = font_list.DeriveWithHeightUpperBound(location_height); |
| 198 | 211 |
| 199 // Determine the font for use inside the bubbles. The bubble background | 212 // Determine the font for use inside the bubbles. The bubble background |
| 200 // images have 1 px thick edges, which we don't want to overlap. | 213 // images have 1 px thick edges, which we don't want to overlap. |
| 201 const int kBubbleInteriorVerticalPadding = | 214 const int kBubbleInteriorVerticalPadding = |
| 202 ui::MaterialDesignController::IsModeMaterial() ? 2 : 1; | 215 ui::MaterialDesignController::IsModeMaterial() ? 2 : 1; |
| 203 const int bubble_padding = | 216 const int bubble_padding = |
| 204 GetEdgeThickness() + | 217 GetVerticalEdgeThicknessWithPadding(true) + |
| 205 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + | |
| 206 kBubbleInteriorVerticalPadding; | 218 kBubbleInteriorVerticalPadding; |
| 207 const int bubble_height = GetPreferredSize().height() - (bubble_padding * 2); | 219 const int bubble_height = GetPreferredSize().height() - (bubble_padding * 2); |
| 208 gfx::FontList bubble_font_list = | 220 gfx::FontList bubble_font_list = |
| 209 font_list.DeriveWithHeightUpperBound(bubble_height); | 221 font_list.DeriveWithHeightUpperBound(bubble_height); |
| 210 | 222 |
| 211 const SkColor background_color = GetColor(BACKGROUND); | 223 const SkColor background_color = GetColor(BACKGROUND); |
| 212 location_icon_view_ = | 224 location_icon_view_ = |
| 213 new LocationIconView(bubble_font_list, background_color, this); | 225 new LocationIconView(bubble_font_list, background_color, this); |
| 214 location_icon_view_->set_drag_controller(this); | 226 location_icon_view_->set_drag_controller(this); |
| 215 AddChildView(location_icon_view_); | 227 AddChildView(location_icon_view_); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 const views::ImageView* image = location_icon_view_->GetImageView(); | 462 const views::ImageView* image = location_icon_view_->GetImageView(); |
| 451 // The +1 in the next line creates a 1-px gap between icon and arrow tip. | 463 // The +1 in the next line creates a 1-px gap between icon and arrow tip. |
| 452 int icon_bottom = image->GetImageBounds().bottom() - | 464 int icon_bottom = image->GetImageBounds().bottom() - |
| 453 GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING) + 1; | 465 GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING) + 1; |
| 454 gfx::Point icon_center(image->GetImageBounds().CenterPoint()); | 466 gfx::Point icon_center(image->GetImageBounds().CenterPoint()); |
| 455 gfx::Point point(icon_center.x(), icon_bottom); | 467 gfx::Point point(icon_center.x(), icon_bottom); |
| 456 ConvertPointToTarget(image, this, &point); | 468 ConvertPointToTarget(image, this, &point); |
| 457 return point; | 469 return point; |
| 458 } | 470 } |
| 459 | 471 |
| 460 int LocationBarView::GetInternalHeight(bool use_preferred_size) { | |
| 461 int total_height = | |
| 462 use_preferred_size ? GetPreferredSize().height() : height(); | |
| 463 return std::max(total_height - (VerticalPadding() * 2), 0); | |
| 464 } | |
| 465 | |
| 466 void LocationBarView::GetOmniboxPopupPositioningInfo( | 472 void LocationBarView::GetOmniboxPopupPositioningInfo( |
| 467 gfx::Point* top_left_screen_coord, | 473 gfx::Point* top_left_screen_coord, |
| 468 int* popup_width, | 474 int* popup_width, |
| 469 int* left_margin, | 475 int* left_margin, |
| 470 int* right_margin, | 476 int* right_margin, |
| 471 int top_edge_overlap) { | 477 int top_edge_overlap) { |
| 472 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap); | 478 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap); |
| 473 views::View::ConvertPointToScreen(parent(), top_left_screen_coord); | 479 views::View::ConvertPointToScreen(parent(), top_left_screen_coord); |
| 474 | 480 |
| 475 *popup_width = parent()->width(); | 481 *popup_width = parent()->width(); |
| 476 gfx::Rect location_bar_bounds(bounds()); | 482 gfx::Rect location_bar_bounds(bounds()); |
| 477 location_bar_bounds.Inset(GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS), | 483 location_bar_bounds.Inset(GetHorizontalEdgeThickness(), 0); |
| 478 0); | |
| 479 *left_margin = location_bar_bounds.x(); | 484 *left_margin = location_bar_bounds.x(); |
| 480 *right_margin = *popup_width - location_bar_bounds.right(); | 485 *right_margin = *popup_width - location_bar_bounds.right(); |
| 481 } | 486 } |
| 482 | 487 |
| 483 //////////////////////////////////////////////////////////////////////////////// | 488 //////////////////////////////////////////////////////////////////////////////// |
| 484 // LocationBarView, public LocationBar implementation: | 489 // LocationBarView, public LocationBar implementation: |
| 485 | 490 |
| 486 void LocationBarView::FocusLocation(bool select_all) { | 491 void LocationBarView::FocusLocation(bool select_all) { |
| 487 omnibox_view_->SetFocus(); | 492 omnibox_view_->SetFocus(); |
| 488 if (select_all) | 493 if (select_all) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 505 } | 510 } |
| 506 | 511 |
| 507 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { | 512 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { |
| 508 state->role = ui::AX_ROLE_GROUP; | 513 state->role = ui::AX_ROLE_GROUP; |
| 509 } | 514 } |
| 510 | 515 |
| 511 gfx::Size LocationBarView::GetPreferredSize() const { | 516 gfx::Size LocationBarView::GetPreferredSize() const { |
| 512 // Compute minimum height. | 517 // Compute minimum height. |
| 513 gfx::Size min_size; | 518 gfx::Size min_size; |
| 514 if (ui::MaterialDesignController::IsModeMaterial() || is_popup_mode_) { | 519 if (ui::MaterialDesignController::IsModeMaterial() || is_popup_mode_) { |
| 515 const int height = GetLayoutConstant(LOCATION_BAR_HEIGHT); | 520 min_size.set_height(GetLayoutConstant(LOCATION_BAR_HEIGHT)); |
| 516 const int edge_thickness = views::NonClientFrameView::kClientEdgeThickness; | |
| 517 min_size.set_height(height - (is_popup_mode_ ? (2 * edge_thickness) : 0)); | |
| 518 } else { | 521 } else { |
| 519 min_size = border_painter_->GetMinimumSize(); | 522 min_size = border_painter_->GetMinimumSize(); |
| 520 } | 523 } |
| 521 | 524 |
| 522 if (!IsInitialized()) | 525 if (!IsInitialized()) |
| 523 return min_size; | 526 return min_size; |
| 524 | 527 |
| 525 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); | 528 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); |
| 526 | 529 |
| 527 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 530 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
| 528 | 531 |
| 529 // Compute width of omnibox-leading content. | 532 // Compute width of omnibox-leading content. |
| 530 const int edge_thickness = GetEdgeThickness(); | 533 const int edge_thickness = GetHorizontalEdgeThickness(); |
| 531 int leading_width = edge_thickness; | 534 int leading_width = edge_thickness; |
| 532 if (ShouldShowKeywordBubble()) { | 535 if (ShouldShowKeywordBubble()) { |
| 533 // The selected keyword view can collapse completely. | 536 // The selected keyword view can collapse completely. |
| 534 } else if (ShouldShowEVBubble()) { | 537 } else if (ShouldShowEVBubble()) { |
| 535 leading_width += GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + | 538 leading_width += GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + |
| 536 location_icon_view_->GetMinimumSizeForLabelText( | 539 location_icon_view_->GetMinimumSizeForLabelText( |
| 537 GetToolbarModel()->GetEVCertName()) | 540 GetToolbarModel()->GetEVCertName()) |
| 538 .width(); | 541 .width(); |
| 539 } else { | 542 } else { |
| 540 leading_width += padding + location_icon_view_->GetMinimumSize().width(); | 543 leading_width += padding + location_icon_view_->GetMinimumSize().width(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 563 | 566 |
| 564 void LocationBarView::Layout() { | 567 void LocationBarView::Layout() { |
| 565 if (!IsInitialized()) | 568 if (!IsInitialized()) |
| 566 return; | 569 return; |
| 567 | 570 |
| 568 selected_keyword_view_->SetVisible(false); | 571 selected_keyword_view_->SetVisible(false); |
| 569 location_icon_view_->SetVisible(false); | 572 location_icon_view_->SetVisible(false); |
| 570 keyword_hint_view_->SetVisible(false); | 573 keyword_hint_view_->SetVisible(false); |
| 571 | 574 |
| 572 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 575 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
| 573 const int edge_thickness = GetEdgeThickness(); | 576 const int edge_thickness = GetHorizontalEdgeThickness(); |
| 574 int trailing_edge_item_padding = 0; | 577 int trailing_edge_item_padding = 0; |
| 575 if (!ui::MaterialDesignController::IsModeMaterial()) { | 578 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 576 trailing_edge_item_padding = | 579 trailing_edge_item_padding = |
| 577 item_padding - edge_thickness - omnibox_view_->GetInsets().right(); | 580 item_padding - edge_thickness - omnibox_view_->GetInsets().right(); |
| 578 } | 581 } |
| 579 | 582 |
| 580 LocationBarLayout leading_decorations( | 583 LocationBarLayout leading_decorations( |
| 581 LocationBarLayout::LEFT_EDGE, item_padding, | 584 LocationBarLayout::LEFT_EDGE, item_padding, |
| 582 item_padding - omnibox_view_->GetInsets().left() - | 585 item_padding - omnibox_view_->GetInsets().left() - |
| 583 GetEditLeadingInternalSpace()); | 586 GetEditLeadingInternalSpace()); |
| 584 LocationBarLayout trailing_decorations( | 587 LocationBarLayout trailing_decorations( |
| 585 LocationBarLayout::RIGHT_EDGE, item_padding, trailing_edge_item_padding); | 588 LocationBarLayout::RIGHT_EDGE, item_padding, trailing_edge_item_padding); |
| 586 | 589 |
| 587 const base::string16 keyword(omnibox_view_->model()->keyword()); | 590 const base::string16 keyword(omnibox_view_->model()->keyword()); |
| 588 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 591 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want |
| 589 // to position our child views in this case, because other things may be | 592 // to position our child views in this case, because other things may be |
| 590 // positioned relative to them (e.g. the "bookmark added" bubble if the user | 593 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
| 591 // hits ctrl-d). | 594 // hits ctrl-d). |
| 592 const int bubble_vertical_padding = | 595 const int bubble_vertical_padding = GetVerticalEdgeThicknessWithPadding(true); |
| 593 edge_thickness + GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING); | |
| 594 const int bubble_height = | 596 const int bubble_height = |
| 595 std::max(height() - (bubble_vertical_padding * 2), 0); | 597 std::max(height() - (bubble_vertical_padding * 2), 0); |
| 596 const int bubble_horizontal_padding = | 598 const int bubble_horizontal_padding = |
| 597 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING); | 599 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING); |
| 598 const int location_height = GetInternalHeight(false); | 600 const int vertical_padding = GetVerticalEdgeThicknessWithPadding(false); |
| 599 const int vertical_padding = VerticalPadding(); | 601 const int location_height = std::max(height() - (vertical_padding * 2), 0); |
| 600 | 602 |
| 601 location_icon_view_->SetLabel(base::string16()); | 603 location_icon_view_->SetLabel(base::string16()); |
| 602 location_icon_view_->SetBackground(false); | 604 location_icon_view_->SetBackground(false); |
| 603 if (ShouldShowKeywordBubble()) { | 605 if (ShouldShowKeywordBubble()) { |
| 604 leading_decorations.AddDecoration(bubble_vertical_padding, bubble_height, | 606 leading_decorations.AddDecoration(bubble_vertical_padding, bubble_height, |
| 605 true, 0, bubble_horizontal_padding, | 607 true, 0, bubble_horizontal_padding, |
| 606 item_padding, selected_keyword_view_); | 608 item_padding, selected_keyword_view_); |
| 607 if (selected_keyword_view_->keyword() != keyword) { | 609 if (selected_keyword_view_->keyword() != keyword) { |
| 608 selected_keyword_view_->SetKeyword(keyword); | 610 selected_keyword_view_->SetKeyword(keyword); |
| 609 const TemplateURL* template_url = | 611 const TemplateURL* template_url = |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 | 840 |
| 839 //////////////////////////////////////////////////////////////////////////////// | 841 //////////////////////////////////////////////////////////////////////////////// |
| 840 // LocationBarView, private: | 842 // LocationBarView, private: |
| 841 | 843 |
| 842 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { | 844 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { |
| 843 return view->visible() ? | 845 return view->visible() ? |
| 844 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + | 846 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + |
| 845 view->GetMinimumSize().width()) : 0; | 847 view->GetMinimumSize().width()) : 0; |
| 846 } | 848 } |
| 847 | 849 |
| 848 int LocationBarView::GetEdgeThickness() const { | 850 int LocationBarView::GetHorizontalEdgeThickness() const { |
| 849 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); | 851 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); |
| 850 } | 852 } |
| 851 | 853 |
| 852 int LocationBarView::VerticalPadding() const { | 854 int LocationBarView::GetVerticalEdgeThickness() const { |
| 853 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); | 855 if (ui::MaterialDesignController::IsModeMaterial()) |
| 856 return GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); |
| 857 return is_popup_mode_ ? views::NonClientFrameView::kClientEdgeThickness |
| 858 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); |
| 859 } |
| 860 |
| 861 int LocationBarView::GetVerticalEdgeThicknessWithPadding( |
| 862 bool for_bubble) const { |
| 863 return GetVerticalEdgeThickness() + |
| 864 GetLayoutConstant(for_bubble ? LOCATION_BAR_BUBBLE_VERTICAL_PADDING |
| 865 : LOCATION_BAR_VERTICAL_PADDING); |
| 854 } | 866 } |
| 855 | 867 |
| 856 void LocationBarView::RefreshLocationIcon() { | 868 void LocationBarView::RefreshLocationIcon() { |
| 857 // |omnibox_view_| may not be ready yet if Init() has not been called. The | 869 // |omnibox_view_| may not be ready yet if Init() has not been called. The |
| 858 // icon will be set soon by OnChanged(). | 870 // icon will be set soon by OnChanged(). |
| 859 if (!omnibox_view_) | 871 if (!omnibox_view_) |
| 860 return; | 872 return; |
| 861 | 873 |
| 862 if (ui::MaterialDesignController::IsModeMaterial()) { | 874 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 863 gfx::VectorIconId icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; | 875 gfx::VectorIconId icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 1276 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
| 1265 View::OnPaint(canvas); | 1277 View::OnPaint(canvas); |
| 1266 | 1278 |
| 1267 if (ui::MaterialDesignController::IsModeMaterial() && !is_popup_mode_) | 1279 if (ui::MaterialDesignController::IsModeMaterial() && !is_popup_mode_) |
| 1268 return; // The background and border are painted by our Background. | 1280 return; // The background and border are painted by our Background. |
| 1269 | 1281 |
| 1270 // Fill the location bar background color behind the border. Parts of the | 1282 // Fill the location bar background color behind the border. Parts of the |
| 1271 // border images are meant to rest atop the toolbar background and parts atop | 1283 // border images are meant to rest atop the toolbar background and parts atop |
| 1272 // the omnibox background, so we can't just blindly fill our entire bounds. | 1284 // the omnibox background, so we can't just blindly fill our entire bounds. |
| 1273 gfx::Rect bounds(GetContentsBounds()); | 1285 gfx::Rect bounds(GetContentsBounds()); |
| 1274 const int edge_thickness = GetEdgeThickness(); | 1286 bounds.Inset(GetHorizontalEdgeThickness(), |
| 1275 bounds.Inset(edge_thickness, edge_thickness); | 1287 is_popup_mode_ ? 0 : GetVerticalEdgeThickness()); |
| 1276 SkColor background_color(GetColor(BACKGROUND)); | 1288 SkColor background_color(GetColor(BACKGROUND)); |
| 1277 if (is_popup_mode_) { | 1289 if (!is_popup_mode_) { |
| 1278 canvas->FillRect(bounds, background_color); | |
| 1279 } else { | |
| 1280 SkPaint paint; | 1290 SkPaint paint; |
| 1281 paint.setStyle(SkPaint::kFill_Style); | 1291 paint.setStyle(SkPaint::kFill_Style); |
| 1282 paint.setColor(background_color); | 1292 paint.setColor(background_color); |
| 1283 const int kBorderCornerRadius = 2; | 1293 const int kBorderCornerRadius = 2; |
| 1284 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | 1294 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
| 1285 // The border itself will be drawn in PaintChildren() since it includes an | 1295 // The border itself will be drawn in PaintChildren() since it includes an |
| 1286 // inner shadow which should be drawn over the contents. | 1296 // inner shadow which should be drawn over the contents. |
| 1297 return; |
| 1287 } | 1298 } |
| 1299 |
| 1300 canvas->FillRect(bounds, background_color); |
| 1301 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord()); |
| 1302 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false); |
| 1303 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true); |
| 1288 } | 1304 } |
| 1289 | 1305 |
| 1290 void LocationBarView::PaintChildren(const ui::PaintContext& context) { | 1306 void LocationBarView::PaintChildren(const ui::PaintContext& context) { |
| 1291 View::PaintChildren(context); | 1307 View::PaintChildren(context); |
| 1292 | 1308 |
| 1293 ui::PaintRecorder recorder(context, size()); | 1309 ui::PaintRecorder recorder(context, size()); |
| 1294 | 1310 |
| 1295 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need | 1311 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need |
| 1296 // the focus rect to appear on top of children we paint here rather than | 1312 // the focus rect to appear on top of children we paint here rather than |
| 1297 // OnPaint(). | 1313 // OnPaint(). |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 // LocationBarView, private TemplateURLServiceObserver implementation: | 1394 // LocationBarView, private TemplateURLServiceObserver implementation: |
| 1379 | 1395 |
| 1380 void LocationBarView::OnTemplateURLServiceChanged() { | 1396 void LocationBarView::OnTemplateURLServiceChanged() { |
| 1381 template_url_service_->RemoveObserver(this); | 1397 template_url_service_->RemoveObserver(this); |
| 1382 template_url_service_ = nullptr; | 1398 template_url_service_ = nullptr; |
| 1383 // If the browser is no longer active, let's not show the info bubble, as this | 1399 // If the browser is no longer active, let's not show the info bubble, as this |
| 1384 // would make the browser the active window again. | 1400 // would make the browser the active window again. |
| 1385 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1401 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
| 1386 ShowFirstRunBubble(); | 1402 ShowFirstRunBubble(); |
| 1387 } | 1403 } |
| OLD | NEW |