| 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 18 matching lines...) Expand all Loading... |
| 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/native_theme/native_theme.h" | 33 #include "ui/native_theme/native_theme.h" |
| 34 #include "ui/vector_icons/vector_icons.h" | 34 #include "ui/vector_icons/vector_icons.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" | |
| 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_(new views::ImageButton(this)), |
| 121 find_next_button_(new views::VectorIconButton(this)), | 120 find_next_button_(new views::ImageButton(this)), |
| 122 close_button_(new views::VectorIconButton(this)) { | 121 close_button_(new views::ImageButton(this)) { |
| 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(); | 130 find_previous_button_->SetFocusForPlatform(); |
| 136 find_previous_button_->SetTooltipText( | 131 find_previous_button_->SetTooltipText( |
| 137 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); | 132 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); |
| 138 find_previous_button_->SetAccessibleName( | 133 find_previous_button_->SetAccessibleName( |
| 139 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); | 134 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); |
| 140 AddChildView(find_previous_button_); | 135 AddChildView(find_previous_button_); |
| 141 | 136 |
| 142 find_next_button_->set_id(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON); | 137 find_next_button_->set_id(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON); |
| 143 find_next_button_->SetFocusForPlatform(); | 138 find_next_button_->SetFocusForPlatform(); |
| (...skipping 129 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::ButtonListener 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 { | |
| 311 return GetNativeTheme()->GetSystemColor( | |
| 312 ui::NativeTheme::kColorId_TextfieldDefaultColor); | |
| 313 } | |
| 314 | |
| 315 //////////////////////////////////////////////////////////////////////////////// | 305 //////////////////////////////////////////////////////////////////////////////// |
| 316 // FindBarView, views::TextfieldController implementation: | 306 // FindBarView, views::TextfieldController implementation: |
| 317 | 307 |
| 318 bool FindBarView::HandleKeyEvent(views::Textfield* sender, | 308 bool FindBarView::HandleKeyEvent(views::Textfield* sender, |
| 319 const ui::KeyEvent& key_event) { | 309 const ui::KeyEvent& key_event) { |
| 320 // If the dialog is not visible, there is no reason to process keyboard input. | 310 // If the dialog is not visible, there is no reason to process keyboard input. |
| 321 if (!find_bar_host_->IsVisible()) | 311 if (!find_bar_host_->IsVisible()) |
| 322 return false; | 312 return false; |
| 323 | 313 |
| 324 if (find_bar_host_->MaybeForwardKeyEventToWebpage(key_event)) | 314 if (find_bar_host_->MaybeForwardKeyEventToWebpage(key_event)) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW, | 405 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW, |
| 416 bg_color); | 406 bg_color); |
| 417 set_background(new views::BubbleBackground(border.get())); | 407 set_background(new views::BubbleBackground(border.get())); |
| 418 SetBorder(std::move(border)); | 408 SetBorder(std::move(border)); |
| 419 | 409 |
| 420 match_count_text_->SetBackgroundColor(bg_color); | 410 match_count_text_->SetBackgroundColor(bg_color); |
| 421 SkColor text_color = | 411 SkColor text_color = |
| 422 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); | 412 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 423 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); | 413 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); |
| 424 separator_->SetColor(SkColorSetA(text_color, 0x26)); | 414 separator_->SetColor(SkColorSetA(text_color, 0x26)); |
| 415 |
| 416 const SkColor base_icon_color = GetNativeTheme()->GetSystemColor( |
| 417 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 418 views::SetImageFromVectorIcon(find_previous_button_, kCaretUpIcon, |
| 419 base_icon_color); |
| 420 views::SetImageFromVectorIcon(find_next_button_, kCaretDownIcon, |
| 421 base_icon_color); |
| 422 views::SetImageFromVectorIcon(close_button_, ui::kCloseIcon, base_icon_color); |
| 425 } | 423 } |
| 426 | |
| OLD | NEW |