| 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 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/ui/views/frame/browser_view.h" | 23 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 24 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
| 25 #include "components/strings/grit/components_strings.h" | 25 #include "components/strings/grit/components_strings.h" |
| 26 #include "ui/base/ime/input_method.h" | 26 #include "ui/base/ime/input_method.h" |
| 27 #include "ui/base/ime/text_input_flags.h" | 27 #include "ui/base/ime/text_input_flags.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/base/theme_provider.h" | 29 #include "ui/base/theme_provider.h" |
| 30 #include "ui/events/event.h" | 30 #include "ui/events/event.h" |
| 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_icon_types.h" |
| 33 #include "ui/native_theme/native_theme.h" | 34 #include "ui/native_theme/native_theme.h" |
| 34 #include "ui/vector_icons/vector_icons.h" | 35 #include "ui/vector_icons/vector_icons.h" |
| 35 #include "ui/views/background.h" | 36 #include "ui/views/background.h" |
| 36 #include "ui/views/border.h" | 37 #include "ui/views/border.h" |
| 37 #include "ui/views/bubble/bubble_border.h" | 38 #include "ui/views/bubble/bubble_border.h" |
| 38 #include "ui/views/controls/button/image_button.h" | |
| 39 #include "ui/views/controls/button/vector_icon_button.h" | |
| 40 #include "ui/views/controls/label.h" | 39 #include "ui/views/controls/label.h" |
| 41 #include "ui/views/controls/separator.h" | 40 #include "ui/views/controls/separator.h" |
| 42 #include "ui/views/layout/box_layout.h" | 41 #include "ui/views/layout/box_layout.h" |
| 43 #include "ui/views/painter.h" | 42 #include "ui/views/painter.h" |
| 44 #include "ui/views/view_targeter.h" | 43 #include "ui/views/view_targeter.h" |
| 45 #include "ui/views/widget/widget.h" | 44 #include "ui/views/widget/widget.h" |
| 46 | 45 |
| 47 namespace { | 46 namespace { |
| 48 | 47 |
| 49 // These layout constants are all in dp. | 48 // These layout constants are all in dp. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 109 |
| 111 //////////////////////////////////////////////////////////////////////////////// | 110 //////////////////////////////////////////////////////////////////////////////// |
| 112 // FindBarView, public: | 111 // FindBarView, public: |
| 113 | 112 |
| 114 FindBarView::FindBarView(FindBarHost* host) | 113 FindBarView::FindBarView(FindBarHost* host) |
| 115 : find_bar_host_(host), | 114 : find_bar_host_(host), |
| 116 find_text_(new views::Textfield), | 115 find_text_(new views::Textfield), |
| 117 match_count_text_(new MatchCountLabel()), | 116 match_count_text_(new MatchCountLabel()), |
| 118 focus_forwarder_view_(new FocusForwarderView(find_text_)), | 117 focus_forwarder_view_(new FocusForwarderView(find_text_)), |
| 119 separator_(new views::Separator()), | 118 separator_(new views::Separator()), |
| 120 find_previous_button_(new views::VectorIconButton(this)), | 119 find_previous_button_(CreateButton(kCaretUpIcon)), |
| 121 find_next_button_(new views::VectorIconButton(this)), | 120 find_next_button_(CreateButton(kCaretDownIcon)), |
| 122 close_button_(new views::VectorIconButton(this)) { | 121 close_button_(CreateButton(ui::kCloseIcon)) { |
| 123 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); | 122 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); |
| 124 find_text_->set_default_width_in_chars(kDefaultCharWidth); | 123 find_text_->set_default_width_in_chars(kDefaultCharWidth); |
| 125 find_text_->set_controller(this); | 124 find_text_->set_controller(this); |
| 126 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); | 125 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); |
| 127 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); | 126 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); |
| 128 AddChildView(find_text_); | 127 AddChildView(find_text_); |
| 129 | 128 |
| 130 find_previous_button_->SetIcon(kCaretUpIcon); | |
| 131 find_next_button_->SetIcon(kCaretDownIcon); | |
| 132 close_button_->SetIcon(ui::kCloseIcon); | |
| 133 | |
| 134 find_previous_button_->set_id(VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON); | 129 find_previous_button_->set_id(VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON); |
| 135 find_previous_button_->SetFocusForPlatform(); | |
| 136 find_previous_button_->SetTooltipText( | 130 find_previous_button_->SetTooltipText( |
| 137 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); | 131 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); |
| 138 find_previous_button_->SetAccessibleName( | 132 find_previous_button_->SetAccessibleName( |
| 139 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); | 133 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); |
| 140 AddChildView(find_previous_button_); | 134 AddChildView(find_previous_button_); |
| 141 | 135 |
| 142 find_next_button_->set_id(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON); | 136 find_next_button_->set_id(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON); |
| 143 find_next_button_->SetFocusForPlatform(); | |
| 144 find_next_button_->SetTooltipText( | 137 find_next_button_->SetTooltipText( |
| 145 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); | 138 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); |
| 146 find_next_button_->SetAccessibleName( | 139 find_next_button_->SetAccessibleName( |
| 147 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); | 140 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); |
| 148 AddChildView(find_next_button_); | 141 AddChildView(find_next_button_); |
| 149 | 142 |
| 150 close_button_->set_id(VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON); | 143 close_button_->set_id(VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON); |
| 151 close_button_->SetFocusForPlatform(); | |
| 152 close_button_->SetTooltipText( | 144 close_button_->SetTooltipText( |
| 153 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); | 145 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); |
| 154 close_button_->SetAccessibleName( | 146 close_button_->SetAccessibleName( |
| 155 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 147 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 156 close_button_->SetAnimationDuration(0); | 148 close_button_->SetAnimationDuration(0); |
| 157 AddChildView(close_button_); | 149 AddChildView(close_button_); |
| 158 | 150 |
| 159 AddChildView(focus_forwarder_view_); | 151 AddChildView(focus_forwarder_view_); |
| 160 | 152 |
| 161 EnableCanvasFlippingForRTLUI(true); | 153 EnableCanvasFlippingForRTLUI(true); |
| 162 | 154 |
| 163 match_count_text_->SetEventTargeter( | 155 match_count_text_->SetEventTargeter( |
| 164 base::MakeUnique<views::ViewTargeter>(this)); | 156 base::MakeUnique<views::ViewTargeter>(this)); |
| 165 AddChildViewAt(match_count_text_, 1); | 157 AddChildViewAt(match_count_text_, 1); |
| 166 | 158 |
| 167 separator_->SetBorder(views::CreateEmptyBorder(0, kSeparatorLeftSpacing, 0, | 159 separator_->SetBorder(views::CreateEmptyBorder(0, kSeparatorLeftSpacing, 0, |
| 168 kSeparatorRightSpacing)); | 160 kSeparatorRightSpacing)); |
| 161 separator_->SetPreferredHeight(find_text_->GetPreferredSize().height()); |
| 169 AddChildViewAt(separator_, 2); | 162 AddChildViewAt(separator_, 2); |
| 170 | 163 |
| 171 find_text_->SetBorder(views::NullBorder()); | 164 find_text_->SetBorder(views::NullBorder()); |
| 172 | 165 |
| 173 views::BoxLayout* manager = | 166 views::BoxLayout* manager = |
| 174 new views::BoxLayout(views::BoxLayout::kHorizontal, kInteriorPadding, | 167 new views::BoxLayout(views::BoxLayout::kHorizontal, kInteriorPadding, |
| 175 kInteriorPadding, kInterChildSpacing); | 168 kInteriorPadding, kInterChildSpacing); |
| 169 manager->set_cross_axis_alignment( |
| 170 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
| 176 SetLayoutManager(manager); | 171 SetLayoutManager(manager); |
| 177 manager->SetFlexForView(find_text_, 1); | 172 manager->SetFlexForView(find_text_, 1); |
| 178 } | 173 } |
| 179 | 174 |
| 180 FindBarView::~FindBarView() { | 175 FindBarView::~FindBarView() { |
| 181 } | 176 } |
| 182 | 177 |
| 183 void FindBarView::SetFindTextAndSelectedRange( | 178 void FindBarView::SetFindTextAndSelectedRange( |
| 184 const base::string16& find_text, | 179 const base::string16& find_text, |
| 185 const gfx::Range& selected_range) { | 180 const gfx::Range& selected_range) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 // FindBarView, DropdownBarHostDelegate implementation: | 268 // FindBarView, DropdownBarHostDelegate implementation: |
| 274 | 269 |
| 275 void FindBarView::SetFocusAndSelection(bool select_all) { | 270 void FindBarView::SetFocusAndSelection(bool select_all) { |
| 276 find_text_->RequestFocus(); | 271 find_text_->RequestFocus(); |
| 277 GetWidget()->GetInputMethod()->ShowImeIfNeeded(); | 272 GetWidget()->GetInputMethod()->ShowImeIfNeeded(); |
| 278 if (select_all && !find_text_->text().empty()) | 273 if (select_all && !find_text_->text().empty()) |
| 279 find_text_->SelectAll(true); | 274 find_text_->SelectAll(true); |
| 280 } | 275 } |
| 281 | 276 |
| 282 //////////////////////////////////////////////////////////////////////////////// | 277 //////////////////////////////////////////////////////////////////////////////// |
| 283 // FindBarView, views::VectorIconButtonDelegate implementation: | 278 // FindBarView, views::ImageButtonDelegate implementation: |
| 284 | 279 |
| 285 void FindBarView::ButtonPressed( | 280 void FindBarView::ButtonPressed( |
| 286 views::Button* sender, const ui::Event& event) { | 281 views::Button* sender, const ui::Event& event) { |
| 287 switch (sender->id()) { | 282 switch (sender->id()) { |
| 288 case VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON: | 283 case VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON: |
| 289 case VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON: | 284 case VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON: |
| 290 if (!find_text_->text().empty()) { | 285 if (!find_text_->text().empty()) { |
| 291 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents( | 286 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents( |
| 292 find_bar_host_->GetFindBarController()->web_contents()); | 287 find_bar_host_->GetFindBarController()->web_contents()); |
| 293 find_tab_helper->StartFinding( | 288 find_tab_helper->StartFinding( |
| 294 find_text_->text(), | 289 find_text_->text(), |
| 295 sender->id() == VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON, | 290 sender->id() == VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON, |
| 296 false); // Not case sensitive. | 291 false); // Not case sensitive. |
| 297 } | 292 } |
| 298 break; | 293 break; |
| 299 case VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON: | 294 case VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON: |
| 300 find_bar_host_->GetFindBarController()->EndFindSession( | 295 find_bar_host_->GetFindBarController()->EndFindSession( |
| 301 FindBarController::kKeepSelectionOnPage, | 296 FindBarController::kKeepSelectionOnPage, |
| 302 FindBarController::kKeepResultsInFindBox); | 297 FindBarController::kKeepResultsInFindBox); |
| 303 break; | 298 break; |
| 304 default: | 299 default: |
| 305 NOTREACHED() << "Unknown button"; | 300 NOTREACHED() << "Unknown button"; |
| 306 break; | 301 break; |
| 307 } | 302 } |
| 308 } | 303 } |
| 309 | 304 |
| 310 SkColor FindBarView::GetVectorIconBaseColor() const { | 305 SkColor FindBarView::GetVectorIconColor() const { |
| 311 return GetNativeTheme()->GetSystemColor( | 306 return GetNativeTheme()->GetSystemColor( |
| 312 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 307 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 313 } | 308 } |
| 314 | 309 |
| 315 //////////////////////////////////////////////////////////////////////////////// | 310 //////////////////////////////////////////////////////////////////////////////// |
| 316 // FindBarView, views::TextfieldController implementation: | 311 // FindBarView, views::TextfieldController implementation: |
| 317 | 312 |
| 318 bool FindBarView::HandleKeyEvent(views::Textfield* sender, | 313 bool FindBarView::HandleKeyEvent(views::Textfield* sender, |
| 319 const ui::KeyEvent& key_event) { | 314 const ui::KeyEvent& key_event) { |
| 320 // If the dialog is not visible, there is no reason to process keyboard input. | 315 // If the dialog is not visible, there is no reason to process keyboard input. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 find_bar_state->set_last_prepopulate_text(base::string16()); | 392 find_bar_state->set_last_prepopulate_text(base::string16()); |
| 398 } | 393 } |
| 399 } | 394 } |
| 400 | 395 |
| 401 void FindBarView::UpdateMatchCountAppearance(bool no_match) { | 396 void FindBarView::UpdateMatchCountAppearance(bool no_match) { |
| 402 bool enable_buttons = !find_text_->text().empty() && !no_match; | 397 bool enable_buttons = !find_text_->text().empty() && !no_match; |
| 403 find_previous_button_->SetEnabled(enable_buttons); | 398 find_previous_button_->SetEnabled(enable_buttons); |
| 404 find_next_button_->SetEnabled(enable_buttons); | 399 find_next_button_->SetEnabled(enable_buttons); |
| 405 } | 400 } |
| 406 | 401 |
| 402 views::ImageButton* FindBarView::CreateButton(const gfx::VectorIcon& icon) { |
| 403 views::ImageButton* button = |
| 404 views::ImageButton::CreateDefaultVectorIconButton(icon, this); |
| 405 button->SetFocusForPlatform(); |
| 406 return button; |
| 407 } |
| 408 |
| 407 const char* FindBarView::GetClassName() const { | 409 const char* FindBarView::GetClassName() const { |
| 408 return "FindBarView"; | 410 return "FindBarView"; |
| 409 } | 411 } |
| 410 | 412 |
| 411 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 413 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 412 SkColor bg_color = theme->GetSystemColor( | 414 SkColor bg_color = theme->GetSystemColor( |
| 413 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | 415 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| 414 auto border = base::MakeUnique<views::BubbleBorder>( | 416 auto border = base::MakeUnique<views::BubbleBorder>( |
| 415 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW, | 417 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW, |
| 416 bg_color); | 418 bg_color); |
| 417 set_background(new views::BubbleBackground(border.get())); | 419 set_background(new views::BubbleBackground(border.get())); |
| 418 SetBorder(std::move(border)); | 420 SetBorder(std::move(border)); |
| 419 | 421 |
| 420 match_count_text_->SetBackgroundColor(bg_color); | 422 match_count_text_->SetBackgroundColor(bg_color); |
| 421 SkColor text_color = | 423 SkColor text_color = |
| 422 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); | 424 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 423 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); | 425 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); |
| 424 separator_->SetColor(SkColorSetA(text_color, 0x26)); | 426 separator_->SetColor(SkColorSetA(text_color, 0x26)); |
| 425 } | 427 } |
| 426 | 428 |
| OLD | NEW |