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" |
| (...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 button_observer_(this), |
| 121 find_next_button_(new views::VectorIconButton(this)), | 120 find_previous_button_(CreateButton(kCaretUpIcon)), |
| 122 close_button_(new views::VectorIconButton(this)) { | 121 find_next_button_(CreateButton(kCaretDownIcon)), |
| 122 close_button_(CreateButton(ui::kCloseIcon)) { | |
| 123 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); | 123 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); |
| 124 find_text_->set_default_width_in_chars(kDefaultCharWidth); | 124 find_text_->set_default_width_in_chars(kDefaultCharWidth); |
| 125 find_text_->set_controller(this); | 125 find_text_->set_controller(this); |
| 126 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); | 126 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); |
| 127 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); | 127 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); |
| 128 AddChildView(find_text_); | 128 AddChildView(find_text_); |
| 129 | 129 |
| 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); | 130 find_previous_button_->set_id(VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON); |
| 135 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(); | |
| 144 find_next_button_->SetTooltipText( | 138 find_next_button_->SetTooltipText( |
| 145 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); | 139 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); |
| 146 find_next_button_->SetAccessibleName( | 140 find_next_button_->SetAccessibleName( |
| 147 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); | 141 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); |
| 148 AddChildView(find_next_button_); | 142 AddChildView(find_next_button_); |
| 149 | 143 |
| 150 close_button_->set_id(VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON); | 144 close_button_->set_id(VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON); |
| 151 close_button_->SetFocusForPlatform(); | |
| 152 close_button_->SetTooltipText( | 145 close_button_->SetTooltipText( |
| 153 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); | 146 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); |
| 154 close_button_->SetAccessibleName( | 147 close_button_->SetAccessibleName( |
| 155 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 148 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 156 close_button_->SetAnimationDuration(0); | 149 close_button_->SetAnimationDuration(0); |
| 157 AddChildView(close_button_); | 150 AddChildView(close_button_); |
| 158 | 151 |
| 159 AddChildView(focus_forwarder_view_); | 152 AddChildView(focus_forwarder_view_); |
| 160 | 153 |
| 161 EnableCanvasFlippingForRTLUI(true); | 154 EnableCanvasFlippingForRTLUI(true); |
| 162 | 155 |
| 163 match_count_text_->SetEventTargeter( | 156 match_count_text_->SetEventTargeter( |
| 164 base::MakeUnique<views::ViewTargeter>(this)); | 157 base::MakeUnique<views::ViewTargeter>(this)); |
| 165 AddChildViewAt(match_count_text_, 1); | 158 AddChildViewAt(match_count_text_, 1); |
| 166 | 159 |
| 167 separator_->SetBorder(views::CreateEmptyBorder(0, kSeparatorLeftSpacing, 0, | 160 separator_->SetBorder(views::CreateEmptyBorder(0, kSeparatorLeftSpacing, 0, |
| 168 kSeparatorRightSpacing)); | 161 kSeparatorRightSpacing)); |
| 162 separator_->SetPreferredHeight(find_text_->GetPreferredSize().height()); | |
| 169 AddChildViewAt(separator_, 2); | 163 AddChildViewAt(separator_, 2); |
| 170 | 164 |
| 171 find_text_->SetBorder(views::NullBorder()); | 165 find_text_->SetBorder(views::NullBorder()); |
| 172 | 166 |
| 173 views::BoxLayout* manager = | 167 views::BoxLayout* manager = |
| 174 new views::BoxLayout(views::BoxLayout::kHorizontal, kInteriorPadding, | 168 new views::BoxLayout(views::BoxLayout::kHorizontal, kInteriorPadding, |
| 175 kInteriorPadding, kInterChildSpacing); | 169 kInteriorPadding, kInterChildSpacing); |
| 170 manager->set_cross_axis_alignment( | |
| 171 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 176 SetLayoutManager(manager); | 172 SetLayoutManager(manager); |
| 177 manager->SetFlexForView(find_text_, 1); | 173 manager->SetFlexForView(find_text_, 1); |
| 178 } | 174 } |
| 179 | 175 |
| 180 FindBarView::~FindBarView() { | 176 FindBarView::~FindBarView() { |
| 181 } | 177 } |
| 182 | 178 |
| 183 void FindBarView::SetFindTextAndSelectedRange( | 179 void FindBarView::SetFindTextAndSelectedRange( |
| 184 const base::string16& find_text, | 180 const base::string16& find_text, |
| 185 const gfx::Range& selected_range) { | 181 const gfx::Range& selected_range) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 find_bar_host_->GetFindBarController()->EndFindSession( | 296 find_bar_host_->GetFindBarController()->EndFindSession( |
| 301 FindBarController::kKeepSelectionOnPage, | 297 FindBarController::kKeepSelectionOnPage, |
| 302 FindBarController::kKeepResultsInFindBox); | 298 FindBarController::kKeepResultsInFindBox); |
| 303 break; | 299 break; |
| 304 default: | 300 default: |
| 305 NOTREACHED() << "Unknown button"; | 301 NOTREACHED() << "Unknown button"; |
| 306 break; | 302 break; |
| 307 } | 303 } |
| 308 } | 304 } |
| 309 | 305 |
| 310 SkColor FindBarView::GetVectorIconBaseColor() const { | |
| 311 return GetNativeTheme()->GetSystemColor( | |
| 312 ui::NativeTheme::kColorId_TextfieldDefaultColor); | |
| 313 } | |
| 314 | |
| 315 //////////////////////////////////////////////////////////////////////////////// | 306 //////////////////////////////////////////////////////////////////////////////// |
| 316 // FindBarView, views::TextfieldController implementation: | 307 // FindBarView, views::TextfieldController implementation: |
| 317 | 308 |
| 318 bool FindBarView::HandleKeyEvent(views::Textfield* sender, | 309 bool FindBarView::HandleKeyEvent(views::Textfield* sender, |
| 319 const ui::KeyEvent& key_event) { | 310 const ui::KeyEvent& key_event) { |
| 320 // If the dialog is not visible, there is no reason to process keyboard input. | 311 // If the dialog is not visible, there is no reason to process keyboard input. |
| 321 if (!find_bar_host_->IsVisible()) | 312 if (!find_bar_host_->IsVisible()) |
| 322 return false; | 313 return false; |
| 323 | 314 |
| 324 if (find_bar_host_->MaybeForwardKeyEventToWebpage(key_event)) | 315 if (find_bar_host_->MaybeForwardKeyEventToWebpage(key_event)) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 355 // a paste operation, even if the pasted text is the same as before. | 346 // a paste operation, even if the pasted text is the same as before. |
| 356 // See http://crbug.com/79002 | 347 // See http://crbug.com/79002 |
| 357 last_searched_text_.clear(); | 348 last_searched_text_.clear(); |
| 358 } | 349 } |
| 359 | 350 |
| 360 views::View* FindBarView::TargetForRect(View* root, const gfx::Rect& rect) { | 351 views::View* FindBarView::TargetForRect(View* root, const gfx::Rect& rect) { |
| 361 DCHECK_EQ(match_count_text_, root); | 352 DCHECK_EQ(match_count_text_, root); |
| 362 return find_text_; | 353 return find_text_; |
| 363 } | 354 } |
| 364 | 355 |
| 356 FindBarView::FindBarViewButtonObserver::FindBarViewButtonObserver( | |
| 357 FindBarView* parent) | |
| 358 : parent_(parent) {} | |
| 359 | |
| 360 const gfx::VectorIcon& FindBarView::FindBarViewButtonObserver::GetVectorIcon( | |
| 361 View* view) const { | |
| 362 if (view == parent_->find_previous_button_) | |
|
Evan Stade
2017/03/15 22:50:43
to elaborate, this is also objectionable in my eye
| |
| 363 return kCaretUpIcon; | |
| 364 if (view == parent_->find_next_button_) | |
| 365 return kCaretDownIcon; | |
| 366 return ui::kCloseIcon; | |
| 367 } | |
| 368 | |
| 369 SkColor FindBarView::FindBarViewButtonObserver::GetVectorIconColor() const { | |
| 370 return parent_->GetNativeTheme()->GetSystemColor( | |
| 371 ui::NativeTheme::kColorId_TextfieldDefaultColor); | |
| 372 } | |
| 373 | |
| 374 views::ImageButton* FindBarView::CreateButton(const gfx::VectorIcon& icon) { | |
| 375 views::ImageButton* button = | |
| 376 views::CreateDefaultVectorIconButton(icon, &button_observer_, this); | |
| 377 button->SetFocusForPlatform(); | |
| 378 return button; | |
| 379 } | |
| 380 | |
| 365 void FindBarView::Find(const base::string16& search_text) { | 381 void FindBarView::Find(const base::string16& search_text) { |
| 366 FindBarController* controller = find_bar_host_->GetFindBarController(); | 382 FindBarController* controller = find_bar_host_->GetFindBarController(); |
| 367 DCHECK(controller); | 383 DCHECK(controller); |
| 368 content::WebContents* web_contents = controller->web_contents(); | 384 content::WebContents* web_contents = controller->web_contents(); |
| 369 // We must guard against a NULL web_contents, which can happen if the text | 385 // We must guard against a NULL web_contents, which can happen if the text |
| 370 // in the Find box is changed right after the tab is destroyed. Otherwise, it | 386 // in the Find box is changed right after the tab is destroyed. Otherwise, it |
| 371 // can lead to crashes, as exposed by automation testing in issue 8048. | 387 // can lead to crashes, as exposed by automation testing in issue 8048. |
| 372 if (!web_contents) | 388 if (!web_contents) |
| 373 return; | 389 return; |
| 374 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents); | 390 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 set_background(new views::BubbleBackground(border.get())); | 433 set_background(new views::BubbleBackground(border.get())); |
| 418 SetBorder(std::move(border)); | 434 SetBorder(std::move(border)); |
| 419 | 435 |
| 420 match_count_text_->SetBackgroundColor(bg_color); | 436 match_count_text_->SetBackgroundColor(bg_color); |
| 421 SkColor text_color = | 437 SkColor text_color = |
| 422 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); | 438 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 423 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); | 439 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); |
| 424 separator_->SetColor(SkColorSetA(text_color, 0x26)); | 440 separator_->SetColor(SkColorSetA(text_color, 0x26)); |
| 425 } | 441 } |
| 426 | 442 |
| OLD | NEW |