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/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" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "chrome/app/vector_icons/vector_icons.h" | 13 #include "chrome/app/vector_icons/vector_icons.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/themes/theme_properties.h" | 15 #include "chrome/browser/themes/theme_properties.h" |
| 16 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 16 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 17 #include "chrome/browser/ui/find_bar/find_bar_state.h" | 17 #include "chrome/browser/ui/find_bar/find_bar_state.h" |
| 18 #include "chrome/browser/ui/find_bar/find_bar_state_factory.h" | 18 #include "chrome/browser/ui/find_bar/find_bar_state_factory.h" |
| 19 #include "chrome/browser/ui/find_bar/find_notification_details.h" | 19 #include "chrome/browser/ui/find_bar/find_notification_details.h" |
| 20 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 20 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| 21 #include "chrome/browser/ui/view_ids.h" | 21 #include "chrome/browser/ui/view_ids.h" |
| 22 #include "chrome/browser/ui/views/find_bar_host.h" | 22 #include "chrome/browser/ui/views/find_bar_host.h" |
| 23 #include "chrome/browser/ui/views/frame/browser_view.h" | 23 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 24 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" | |
| 24 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
| 25 #include "components/strings/grit/components_strings.h" | 26 #include "components/strings/grit/components_strings.h" |
| 26 #include "ui/base/ime/input_method.h" | 27 #include "ui/base/ime/input_method.h" |
| 27 #include "ui/base/ime/text_input_flags.h" | 28 #include "ui/base/ime/text_input_flags.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/base/theme_provider.h" | 30 #include "ui/base/theme_provider.h" |
| 30 #include "ui/events/event.h" | 31 #include "ui/events/event.h" |
| 31 #include "ui/gfx/color_palette.h" | 32 #include "ui/gfx/color_palette.h" |
| 32 #include "ui/gfx/geometry/insets.h" | 33 #include "ui/gfx/geometry/insets.h" |
| 33 #include "ui/gfx/paint_vector_icon.h" | 34 #include "ui/gfx/paint_vector_icon.h" |
| 34 #include "ui/native_theme/native_theme.h" | 35 #include "ui/native_theme/native_theme.h" |
| 35 #include "ui/vector_icons/vector_icons.h" | 36 #include "ui/vector_icons/vector_icons.h" |
| 36 #include "ui/views/background.h" | 37 #include "ui/views/background.h" |
| 37 #include "ui/views/border.h" | 38 #include "ui/views/border.h" |
| 38 #include "ui/views/bubble/bubble_border.h" | 39 #include "ui/views/bubble/bubble_border.h" |
| 39 #include "ui/views/controls/button/image_button.h" | 40 #include "ui/views/controls/button/image_button.h" |
| 40 #include "ui/views/controls/button/image_button_factory.h" | 41 #include "ui/views/controls/button/image_button_factory.h" |
| 41 #include "ui/views/controls/label.h" | 42 #include "ui/views/controls/label.h" |
| 42 #include "ui/views/controls/separator.h" | 43 #include "ui/views/controls/separator.h" |
| 43 #include "ui/views/layout/box_layout.h" | 44 #include "ui/views/layout/box_layout.h" |
| 44 #include "ui/views/painter.h" | 45 #include "ui/views/painter.h" |
| 46 #include "ui/views/view_properties.h" | |
| 45 #include "ui/views/view_targeter.h" | 47 #include "ui/views/view_targeter.h" |
| 46 #include "ui/views/widget/widget.h" | 48 #include "ui/views/widget/widget.h" |
| 47 | 49 |
| 48 namespace { | 50 namespace { |
| 49 | 51 |
| 50 // These layout constants are all in dp. | |
| 51 // The horizontal and vertical insets for the bar. | |
| 52 const int kInteriorPadding = 8; | |
| 53 // Default spacing between child views. | |
| 54 const int kInterChildSpacing = 4; | |
| 55 // Additional spacing around the separator. | |
| 56 const int kSeparatorLeftSpacing = 12 - kInterChildSpacing; | |
| 57 const int kSeparatorRightSpacing = 8 - kInterChildSpacing; | |
| 58 | |
| 59 // The default number of average characters that the text box will be. | 52 // The default number of average characters that the text box will be. |
| 60 const int kDefaultCharWidth = 30; | 53 const int kDefaultCharWidth = 30; |
| 61 | 54 |
| 62 // The match count label is like a normal label, but can process events (which | 55 // The match count label is like a normal label, but can process events (which |
| 63 // makes it easier to forward events to the text input --- see | 56 // makes it easier to forward events to the text input --- see |
| 64 // FindBarView::TargetForRect). | 57 // FindBarView::TargetForRect). |
| 65 class MatchCountLabel : public views::Label { | 58 class MatchCountLabel : public views::Label { |
| 66 public: | 59 public: |
| 67 MatchCountLabel() {} | 60 MatchCountLabel() {} |
| 68 ~MatchCountLabel() override {} | 61 ~MatchCountLabel() override {} |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 AddChildView(close_button_); | 147 AddChildView(close_button_); |
| 155 | 148 |
| 156 AddChildView(focus_forwarder_view_); | 149 AddChildView(focus_forwarder_view_); |
| 157 | 150 |
| 158 EnableCanvasFlippingForRTLUI(true); | 151 EnableCanvasFlippingForRTLUI(true); |
| 159 | 152 |
| 160 match_count_text_->SetEventTargeter( | 153 match_count_text_->SetEventTargeter( |
| 161 base::MakeUnique<views::ViewTargeter>(this)); | 154 base::MakeUnique<views::ViewTargeter>(this)); |
| 162 AddChildViewAt(match_count_text_, 1); | 155 AddChildViewAt(match_count_text_, 1); |
| 163 | 156 |
| 164 separator_->SetBorder(views::CreateEmptyBorder(0, kSeparatorLeftSpacing, 0, | 157 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); |
| 165 kSeparatorRightSpacing)); | 158 |
| 159 // We use the same border as the image button for the separator to make it | |
| 160 // equidistant from the match count text on the left and the image button on | |
| 161 // the right. | |
| 162 gfx::Insets image_button_insets = provider->GetInsetsMetric( | |
| 163 views::INSETS_VECTOR_IMAGE_BUTTON); | |
| 164 separator_->SetBorder(views::CreateEmptyBorder(0, image_button_insets.left(), | |
| 165 0, image_button_insets.right())); | |
|
Peter Kasting
2017/07/14 00:40:12
This won't make things equidistant (as is visible
ananta
2017/07/14 01:04:29
ok. thanks. The patch came out wrong though. I was
| |
| 166 | |
| 166 AddChildViewAt(separator_, 2); | 167 AddChildViewAt(separator_, 2); |
| 167 | 168 |
| 169 find_previous_button_->SetProperty(views::kMarginsKey, new gfx::Insets( | |
| 170 provider->GetDistanceMetric(DISTANCE_TOAST_CONTROL_VERTICAL), 0)); | |
| 171 find_next_button_->SetProperty(views::kMarginsKey, new gfx::Insets( | |
| 172 provider->GetDistanceMetric(DISTANCE_TOAST_CONTROL_VERTICAL), 0)); | |
| 173 close_button_->SetProperty(views::kMarginsKey, new gfx::Insets( | |
| 174 provider->GetDistanceMetric(DISTANCE_TOAST_CONTROL_VERTICAL), 0)); | |
| 175 find_text_->SetProperty(views::kMarginsKey, new gfx::Insets( | |
| 176 provider->GetDistanceMetric(DISTANCE_TOAST_CONTROL_VERTICAL), 0)); | |
| 177 match_count_text_->SetProperty(views::kMarginsKey, new gfx::Insets( | |
| 178 provider->GetDistanceMetric(DISTANCE_TOAST_LABEL_VERTICAL), 0)); | |
| 179 separator_->SetProperty(views::kMarginsKey, new gfx::Insets( | |
| 180 provider->GetDistanceMetric(DISTANCE_TOAST_LABEL_VERTICAL), 0)); | |
| 181 | |
| 168 find_text_->SetBorder(views::NullBorder()); | 182 find_text_->SetBorder(views::NullBorder()); |
| 169 | 183 |
| 170 views::BoxLayout* manager = | 184 views::BoxLayout* manager = |
| 171 new views::BoxLayout(views::BoxLayout::kHorizontal, | 185 new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 172 gfx::Insets(kInteriorPadding), kInterChildSpacing); | 186 provider->GetInsetsMetric(views::INSETS_TOAST), |
| 187 provider->GetDistanceMetric( | |
| 188 views::DISTANCE_RELATED_CONTROL_HORIZONTAL)); | |
| 173 SetLayoutManager(manager); | 189 SetLayoutManager(manager); |
| 174 manager->SetFlexForView(find_text_, 1); | 190 manager->SetFlexForView(find_text_, 1); |
| 175 } | 191 } |
| 176 | 192 |
| 177 FindBarView::~FindBarView() { | 193 FindBarView::~FindBarView() { |
| 178 } | 194 } |
| 179 | 195 |
| 180 void FindBarView::SetFindTextAndSelectedRange( | 196 void FindBarView::SetFindTextAndSelectedRange( |
| 181 const base::string16& find_text, | 197 const base::string16& find_text, |
| 182 const gfx::Range& selected_range) { | 198 const gfx::Range& selected_range) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 213 find_text_->SelectAll(true); | 229 find_text_->SelectAll(true); |
| 214 } | 230 } |
| 215 | 231 |
| 216 if (find_text.empty() || !have_valid_range) { | 232 if (find_text.empty() || !have_valid_range) { |
| 217 // If there was no text entered, we don't show anything in the result count | 233 // If there was no text entered, we don't show anything in the result count |
| 218 // area. | 234 // area. |
| 219 ClearMatchCount(); | 235 ClearMatchCount(); |
| 220 return; | 236 return; |
| 221 } | 237 } |
| 222 | 238 |
| 223 match_count_text_->SetText(l10n_util::GetStringFUTF16( | 239 match_count_text_->SetText(l10n_util::GetStringFUTF16(IDS_FIND_IN_PAGE_COUNT, |
| 224 IDS_FIND_IN_PAGE_COUNT, base::FormatNumber(result.active_match_ordinal()), | 240 base::FormatNumber(result.active_match_ordinal()), |
| 225 base::FormatNumber(result.number_of_matches()))); | 241 base::FormatNumber(result.number_of_matches()))); |
| 226 | 242 |
| 227 UpdateMatchCountAppearance(result.number_of_matches() == 0 && | 243 UpdateMatchCountAppearance(result.number_of_matches() == 0 && |
| 228 result.final_update()); | 244 result.final_update()); |
| 229 | 245 |
| 230 // The match_count label may have increased/decreased in size so we need to | 246 // The match_count label may have increased/decreased in size so we need to |
| 231 // do a layout and repaint the dialog so that the find text field doesn't | 247 // do a layout and repaint the dialog so that the find text field doesn't |
| 232 // partially overlap the match-count label when it increases on no matches. | 248 // partially overlap the match-count label when it increases on no matches. |
| 233 Layout(); | 249 Layout(); |
| 234 SchedulePaint(); | 250 SchedulePaint(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 separator_->SetColor(SkColorSetA(text_color, 0x26)); | 432 separator_->SetColor(SkColorSetA(text_color, 0x26)); |
| 417 | 433 |
| 418 const SkColor base_icon_color = GetNativeTheme()->GetSystemColor( | 434 const SkColor base_icon_color = GetNativeTheme()->GetSystemColor( |
| 419 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 435 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 420 views::SetImageFromVectorIcon(find_previous_button_, kCaretUpIcon, | 436 views::SetImageFromVectorIcon(find_previous_button_, kCaretUpIcon, |
| 421 base_icon_color); | 437 base_icon_color); |
| 422 views::SetImageFromVectorIcon(find_next_button_, kCaretDownIcon, | 438 views::SetImageFromVectorIcon(find_next_button_, kCaretDownIcon, |
| 423 base_icon_color); | 439 base_icon_color); |
| 424 views::SetImageFromVectorIcon(close_button_, ui::kCloseIcon, base_icon_color); | 440 views::SetImageFromVectorIcon(close_button_, ui::kCloseIcon, base_icon_color); |
| 425 } | 441 } |
| OLD | NEW |