| 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_(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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 30 matching lines...) Expand all Loading... |
| 355 // a paste operation, even if the pasted text is the same as before. | 345 // a paste operation, even if the pasted text is the same as before. |
| 356 // See http://crbug.com/79002 | 346 // See http://crbug.com/79002 |
| 357 last_searched_text_.clear(); | 347 last_searched_text_.clear(); |
| 358 } | 348 } |
| 359 | 349 |
| 360 views::View* FindBarView::TargetForRect(View* root, const gfx::Rect& rect) { | 350 views::View* FindBarView::TargetForRect(View* root, const gfx::Rect& rect) { |
| 361 DCHECK_EQ(match_count_text_, root); | 351 DCHECK_EQ(match_count_text_, root); |
| 362 return find_text_; | 352 return find_text_; |
| 363 } | 353 } |
| 364 | 354 |
| 355 FindBarView::FindBarViewButtonImageUpdater::FindBarViewButtonImageUpdater( |
| 356 const gfx::VectorIcon& icon, |
| 357 FindBarView* parent) |
| 358 : VectorIconImageUpdater(icon), parent_(parent) {} |
| 359 |
| 360 SkColor FindBarView::FindBarViewButtonImageUpdater::GetVectorIconColor() const { |
| 361 return parent_->GetNativeTheme()->GetSystemColor( |
| 362 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 363 } |
| 364 |
| 365 views::ImageButton* FindBarView::CreateButton(const gfx::VectorIcon& icon) { |
| 366 views::ImageButton* button = views::CreateImageButtonWithImageUpdater( |
| 367 new FindBarViewButtonImageUpdater(icon, this), this); |
| 368 button->SetFocusForPlatform(); |
| 369 return button; |
| 370 } |
| 371 |
| 365 void FindBarView::Find(const base::string16& search_text) { | 372 void FindBarView::Find(const base::string16& search_text) { |
| 366 FindBarController* controller = find_bar_host_->GetFindBarController(); | 373 FindBarController* controller = find_bar_host_->GetFindBarController(); |
| 367 DCHECK(controller); | 374 DCHECK(controller); |
| 368 content::WebContents* web_contents = controller->web_contents(); | 375 content::WebContents* web_contents = controller->web_contents(); |
| 369 // We must guard against a NULL web_contents, which can happen if the text | 376 // 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 | 377 // 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. | 378 // can lead to crashes, as exposed by automation testing in issue 8048. |
| 372 if (!web_contents) | 379 if (!web_contents) |
| 373 return; | 380 return; |
| 374 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents); | 381 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())); | 424 set_background(new views::BubbleBackground(border.get())); |
| 418 SetBorder(std::move(border)); | 425 SetBorder(std::move(border)); |
| 419 | 426 |
| 420 match_count_text_->SetBackgroundColor(bg_color); | 427 match_count_text_->SetBackgroundColor(bg_color); |
| 421 SkColor text_color = | 428 SkColor text_color = |
| 422 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); | 429 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 423 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); | 430 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); |
| 424 separator_->SetColor(SkColorSetA(text_color, 0x26)); | 431 separator_->SetColor(SkColorSetA(text_color, 0x26)); |
| 425 } | 432 } |
| 426 | 433 |
| OLD | NEW |