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/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/themes/theme_properties.h" | 14 #include "chrome/browser/themes/theme_properties.h" |
| 15 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 15 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 16 #include "chrome/browser/ui/find_bar/find_bar_state.h" | 16 #include "chrome/browser/ui/find_bar/find_bar_state.h" |
| 17 #include "chrome/browser/ui/find_bar/find_bar_state_factory.h" | 17 #include "chrome/browser/ui/find_bar/find_bar_state_factory.h" |
| 18 #include "chrome/browser/ui/find_bar/find_notification_details.h" | 18 #include "chrome/browser/ui/find_bar/find_notification_details.h" |
| 19 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 19 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| 20 #include "chrome/browser/ui/view_ids.h" | 20 #include "chrome/browser/ui/view_ids.h" |
| 21 #include "chrome/browser/ui/views/find_bar_host.h" | 21 #include "chrome/browser/ui/views/find_bar_host.h" |
| 22 #include "chrome/browser/ui/views/frame/browser_view.h" | 22 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 23 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 24 #include "components/strings/grit/components_strings.h" | 24 #include "components/strings/grit/components_strings.h" |
| 25 #include "ui/base/ime/input_method.h" | 25 #include "ui/base/ime/input_method.h" |
| 26 #include "ui/base/ime/text_input_flags.h" | 26 #include "ui/base/ime/text_input_flags.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/theme_provider.h" | 28 #include "ui/base/theme_provider.h" |
| 29 #include "ui/events/event.h" | 29 #include "ui/events/event.h" |
| 30 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
|
msw
2016/10/07 01:14:48
nit: remove
Evan Stade
2016/10/10 17:26:31
Done.
| |
| 31 #include "ui/gfx/color_palette.h" | 31 #include "ui/gfx/color_palette.h" |
| 32 #include "ui/gfx/paint_vector_icon.h" | 32 #include "ui/gfx/paint_vector_icon.h" |
| 33 #include "ui/gfx/vector_icons_public.h" | 33 #include "ui/gfx/vector_icons_public.h" |
| 34 #include "ui/native_theme/native_theme.h" | 34 #include "ui/native_theme/native_theme.h" |
| 35 #include "ui/views/background.h" | 35 #include "ui/views/background.h" |
| 36 #include "ui/views/border.h" | 36 #include "ui/views/border.h" |
| 37 #include "ui/views/bubble/bubble_border.h" | 37 #include "ui/views/bubble/bubble_border.h" |
| 38 #include "ui/views/controls/button/image_button.h" | 38 #include "ui/views/controls/button/image_button.h" |
| 39 #include "ui/views/controls/button/vector_icon_button.h" | 39 #include "ui/views/controls/button/vector_icon_button.h" |
| 40 #include "ui/views/controls/label.h" | 40 #include "ui/views/controls/label.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); | 153 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); |
| 154 close_button_->SetAccessibleName( | 154 close_button_->SetAccessibleName( |
| 155 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 155 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 156 close_button_->SetAnimationDuration(0); | 156 close_button_->SetAnimationDuration(0); |
| 157 AddChildView(close_button_); | 157 AddChildView(close_button_); |
| 158 | 158 |
| 159 AddChildView(focus_forwarder_view_); | 159 AddChildView(focus_forwarder_view_); |
| 160 | 160 |
| 161 EnableCanvasFlippingForRTLUI(true); | 161 EnableCanvasFlippingForRTLUI(true); |
| 162 | 162 |
| 163 // The background color is not used since there's no arrow. | |
| 164 SetBorder(base::MakeUnique<views::BubbleBorder>( | |
| 165 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW, | |
| 166 gfx::kPlaceholderColor)); | |
| 167 | |
| 168 match_count_text_->SetEventTargeter( | 163 match_count_text_->SetEventTargeter( |
| 169 base::MakeUnique<views::ViewTargeter>(this)); | 164 base::MakeUnique<views::ViewTargeter>(this)); |
| 170 AddChildViewAt(match_count_text_, 1); | 165 AddChildViewAt(match_count_text_, 1); |
| 171 | 166 |
| 172 separator_->SetBorder(views::Border::CreateEmptyBorder( | 167 separator_->SetBorder(views::Border::CreateEmptyBorder( |
| 173 0, kSeparatorLeftSpacing, 0, kSeparatorRightSpacing)); | 168 0, kSeparatorLeftSpacing, 0, kSeparatorRightSpacing)); |
| 174 AddChildViewAt(separator_, 2); | 169 AddChildViewAt(separator_, 2); |
| 175 | 170 |
| 176 find_text_->SetBorder(views::Border::NullBorder()); | 171 find_text_->SetBorder(views::Border::NullBorder()); |
| 177 | 172 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 void FindBarView::SetFocusAndSelection(bool select_all) { | 247 void FindBarView::SetFocusAndSelection(bool select_all) { |
| 253 find_text_->RequestFocus(); | 248 find_text_->RequestFocus(); |
| 254 GetWidget()->GetInputMethod()->ShowImeIfNeeded(); | 249 GetWidget()->GetInputMethod()->ShowImeIfNeeded(); |
| 255 if (select_all && !find_text_->text().empty()) | 250 if (select_all && !find_text_->text().empty()) |
| 256 find_text_->SelectAll(true); | 251 find_text_->SelectAll(true); |
| 257 } | 252 } |
| 258 | 253 |
| 259 /////////////////////////////////////////////////////////////////////////////// | 254 /////////////////////////////////////////////////////////////////////////////// |
| 260 // FindBarView, views::View overrides: | 255 // FindBarView, views::View overrides: |
| 261 | 256 |
| 262 void FindBarView::OnPaintBackground(gfx::Canvas* canvas) { | |
| 263 // Draw within the lines. | |
| 264 canvas->Save(); | |
| 265 gfx::Rect bounds = GetLocalBounds(); | |
| 266 bounds.Inset(border()->GetInsets()); | |
| 267 canvas->ClipRect(bounds); | |
| 268 views::View::OnPaintBackground(canvas); | |
| 269 canvas->Restore(); | |
| 270 } | |
| 271 | |
| 272 void FindBarView::Layout() { | 257 void FindBarView::Layout() { |
| 273 views::View::Layout(); | 258 views::View::Layout(); |
| 274 | 259 |
| 275 // The focus forwarder view is a hidden view that should cover the area | 260 // The focus forwarder view is a hidden view that should cover the area |
| 276 // between the find text box and the find button so that when the user clicks | 261 // between the find text box and the find button so that when the user clicks |
| 277 // in that area we focus on the find text box. | 262 // in that area we focus on the find text box. |
| 278 const int find_text_edge = find_text_->x() + find_text_->width(); | 263 const int find_text_edge = find_text_->x() + find_text_->width(); |
| 279 focus_forwarder_view_->SetBounds( | 264 focus_forwarder_view_->SetBounds( |
| 280 find_text_edge, find_previous_button_->y(), | 265 find_text_edge, find_previous_button_->y(), |
| 281 find_previous_button_->x() - find_text_edge, | 266 find_previous_button_->x() - find_text_edge, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 return static_cast<FindBarHost*>(host()); | 405 return static_cast<FindBarHost*>(host()); |
| 421 } | 406 } |
| 422 | 407 |
| 423 const char* FindBarView::GetClassName() const { | 408 const char* FindBarView::GetClassName() const { |
| 424 return "FindBarView"; | 409 return "FindBarView"; |
| 425 } | 410 } |
| 426 | 411 |
| 427 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 412 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 428 SkColor bg_color = theme->GetSystemColor( | 413 SkColor bg_color = theme->GetSystemColor( |
| 429 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | 414 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| 430 set_background(views::Background::CreateSolidBackground(bg_color)); | 415 auto border = base::MakeUnique<views::BubbleBorder>( |
| 416 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW, | |
| 417 bg_color); | |
| 418 set_background(new views::BubbleBackground(border.get())); | |
| 419 SetBorder(std::move(border)); | |
| 420 | |
| 431 match_count_text_->SetBackgroundColor(bg_color); | 421 match_count_text_->SetBackgroundColor(bg_color); |
| 432 | |
| 433 SkColor text_color = | 422 SkColor text_color = |
| 434 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); | 423 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 435 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); | 424 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); |
| 436 separator_->SetColor(SkColorSetA(text_color, 0x26)); | 425 separator_->SetColor(SkColorSetA(text_color, 0x26)); |
| 437 } | 426 } |
| 438 | 427 |
| OLD | NEW |