| 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/find_bar_view.h" | 5 #include "chrome/browser/ui/views/find_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/i18n/number_formatting.h" | 9 #include "base/i18n/number_formatting.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 // The text color for the match count label when no matches are found. | 83 // The text color for the match count label when no matches are found. |
| 84 const SkColor kTextColorNoMatch = SK_ColorBLACK; | 84 const SkColor kTextColorNoMatch = SK_ColorBLACK; |
| 85 | 85 |
| 86 // The background color of the match count label when results are found. | 86 // The background color of the match count label when results are found. |
| 87 const SkColor kBackgroundColorMatch = SkColorSetARGB(0, 255, 255, 255); | 87 const SkColor kBackgroundColorMatch = SkColorSetARGB(0, 255, 255, 255); |
| 88 | 88 |
| 89 // The background color of the match count label when no results are found. | 89 // The background color of the match count label when no results are found. |
| 90 const SkColor kBackgroundColorNoMatch = SkColorSetRGB(255, 102, 102); | 90 const SkColor kBackgroundColorNoMatch = SkColorSetRGB(255, 102, 102); |
| 91 | 91 |
| 92 // The default number of average characters that the text box will be. This | 92 // The default number of average characters that the text box will be. |
| 93 // number brings the width on a "regular fonts" system to about 300px. | |
| 94 const int kDefaultCharWidth = 43; | 93 const int kDefaultCharWidth = 43; |
| 94 const int kDefaultCharWidthMd = 26; |
| 95 | 95 |
| 96 // The match count label is like a normal label, but can process events (which | 96 // The match count label is like a normal label, but can process events (which |
| 97 // makes it easier to forward events to the text input --- see | 97 // makes it easier to forward events to the text input --- see |
| 98 // FindBarView::TargetForRect). | 98 // FindBarView::TargetForRect). |
| 99 class MatchCountLabel : public views::Label { | 99 class MatchCountLabel : public views::Label { |
| 100 public: | 100 public: |
| 101 MatchCountLabel() {} | 101 MatchCountLabel() {} |
| 102 ~MatchCountLabel() override {} | 102 ~MatchCountLabel() override {} |
| 103 | 103 |
| 104 // views::Label overrides: | 104 // views::Label overrides: |
| 105 bool CanProcessEventsWithinSubtree() const override { return true; } | 105 bool CanProcessEventsWithinSubtree() const override { return true; } |
| 106 | 106 |
| 107 gfx::Size GetPreferredSize() const override { |
| 108 // We need to return at least 1dip so that box layout adds padding on either |
| 109 // side (otherwise there will be a jump when our size changes between empty |
| 110 // and non-empty). |
| 111 gfx::Size size = views::Label::GetPreferredSize(); |
| 112 size.set_width(std::max(1, size.width())); |
| 113 return size; |
| 114 } |
| 115 |
| 107 private: | 116 private: |
| 108 DISALLOW_COPY_AND_ASSIGN(MatchCountLabel); | 117 DISALLOW_COPY_AND_ASSIGN(MatchCountLabel); |
| 109 }; | 118 }; |
| 110 | 119 |
| 111 } // namespace | 120 } // namespace |
| 112 | 121 |
| 113 //////////////////////////////////////////////////////////////////////////////// | 122 //////////////////////////////////////////////////////////////////////////////// |
| 114 // FindBarView, public: | 123 // FindBarView, public: |
| 115 | 124 |
| 116 FindBarView::FindBarView(FindBarHost* host) | 125 FindBarView::FindBarView(FindBarHost* host) |
| 117 : DropdownBarView(host), | 126 : DropdownBarView(host), |
| 118 find_text_(nullptr), | 127 find_text_(nullptr), |
| 119 match_count_text_(nullptr), | 128 match_count_text_(nullptr), |
| 120 focus_forwarder_view_(nullptr), | 129 focus_forwarder_view_(nullptr), |
| 121 separator_(nullptr), | 130 separator_(nullptr), |
| 122 find_previous_button_(nullptr), | 131 find_previous_button_(nullptr), |
| 123 find_next_button_(nullptr), | 132 find_next_button_(nullptr), |
| 124 close_button_(nullptr) { | 133 close_button_(nullptr) { |
| 125 find_text_ = new views::Textfield; | 134 find_text_ = new views::Textfield; |
| 126 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); | 135 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); |
| 127 find_text_->set_default_width_in_chars(kDefaultCharWidth); | 136 find_text_->set_default_width_in_chars( |
| 137 ui::MaterialDesignController::IsModeMaterial() ? kDefaultCharWidthMd |
| 138 : kDefaultCharWidth); |
| 128 find_text_->set_controller(this); | 139 find_text_->set_controller(this); |
| 129 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); | 140 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); |
| 130 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); | 141 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); |
| 131 AddChildView(find_text_); | 142 AddChildView(find_text_); |
| 132 | 143 |
| 133 if (ui::MaterialDesignController::IsModeMaterial()) { | 144 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 134 BarControlButton* find_previous = new BarControlButton(this); | 145 BarControlButton* find_previous = new BarControlButton(this); |
| 135 find_previous->SetIcon( | 146 find_previous->SetIcon( |
| 136 gfx::VectorIconId::FIND_PREV, | 147 gfx::VectorIconId::FIND_PREV, |
| 137 base::Bind(&FindBarView::GetTextColorForIcon, base::Unretained(this))); | 148 base::Bind(&FindBarView::GetTextColorForIcon, base::Unretained(this))); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // in that area we focus on the find text box. | 393 // in that area we focus on the find text box. |
| 383 const int find_text_edge = find_text_->x() + find_text_->width(); | 394 const int find_text_edge = find_text_->x() + find_text_->width(); |
| 384 focus_forwarder_view_->SetBounds( | 395 focus_forwarder_view_->SetBounds( |
| 385 find_text_edge, find_previous_button_->y(), | 396 find_text_edge, find_previous_button_->y(), |
| 386 find_previous_button_->x() - find_text_edge, | 397 find_previous_button_->x() - find_text_edge, |
| 387 find_previous_button_->height()); | 398 find_previous_button_->height()); |
| 388 } | 399 } |
| 389 | 400 |
| 390 gfx::Size FindBarView::GetPreferredSize() const { | 401 gfx::Size FindBarView::GetPreferredSize() const { |
| 391 if (ui::MaterialDesignController::IsModeMaterial()) { | 402 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 392 // The entire bar is sized to a specific number of characters set on | |
| 393 // |find_text_|. | |
| 394 gfx::Size size = views::View::GetPreferredSize(); | 403 gfx::Size size = views::View::GetPreferredSize(); |
| 395 size.set_width(find_text_->GetPreferredSize().width()); | 404 // Ignore the preferred size for the match count label, and just let it take |
| 405 // up part of the space for the input textfield. This prevents the overall |
| 406 // width from changing every time the match count text changes. |
| 407 size.set_width(size.width() - |
| 408 match_count_text_->GetPreferredSize().width()); |
| 396 return size; | 409 return size; |
| 397 } | 410 } |
| 398 | 411 |
| 399 gfx::Size prefsize = find_text_->GetPreferredSize(); | 412 gfx::Size prefsize = find_text_->GetPreferredSize(); |
| 400 prefsize.set_height(preferred_height_); | 413 prefsize.set_height(preferred_height_); |
| 401 | 414 |
| 402 // Add up all the preferred sizes and margins of the rest of the controls. | 415 // Add up all the preferred sizes and margins of the rest of the controls. |
| 403 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton + | 416 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton + |
| 404 kMarginLeftOfFindTextfield - | 417 kMarginLeftOfFindTextfield - |
| 405 find_text_->GetInsets().width(), | 418 find_text_->GetInsets().width(), |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 SkColor text_color = | 663 SkColor text_color = |
| 651 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); | 664 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 652 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); | 665 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); |
| 653 separator_->SetColor(SkColorSetA(text_color, 0x26)); | 666 separator_->SetColor(SkColorSetA(text_color, 0x26)); |
| 654 } | 667 } |
| 655 | 668 |
| 656 SkColor FindBarView::GetTextColorForIcon() { | 669 SkColor FindBarView::GetTextColorForIcon() { |
| 657 return GetNativeTheme()->GetSystemColor( | 670 return GetNativeTheme()->GetSystemColor( |
| 658 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 671 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 659 } | 672 } |
| OLD | NEW |