Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 2395033002: Harmony - Don't paint focus ring on unless border requests it. (Closed)
Patch Set: override setborder Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/views/controls/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 placeholder_text_color_(kDefaultPlaceholderTextColor), 254 placeholder_text_color_(kDefaultPlaceholderTextColor),
255 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), 255 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT),
256 text_input_flags_(0), 256 text_input_flags_(0),
257 performing_user_action_(false), 257 performing_user_action_(false),
258 skip_input_method_cancel_composition_(false), 258 skip_input_method_cancel_composition_(false),
259 drop_cursor_visible_(false), 259 drop_cursor_visible_(false),
260 initiating_drag_(false), 260 initiating_drag_(false),
261 aggregated_clicks_(0), 261 aggregated_clicks_(0),
262 drag_start_display_offset_(0), 262 drag_start_display_offset_(0),
263 touch_handles_hidden_due_to_scroll_(false), 263 touch_handles_hidden_due_to_scroll_(false),
264 use_focus_ring_(ui::MaterialDesignController::IsSecondaryUiMaterial()),
264 weak_ptr_factory_(this) { 265 weak_ptr_factory_(this) {
265 set_context_menu_controller(this); 266 set_context_menu_controller(this);
266 set_drag_controller(this); 267 set_drag_controller(this);
267 GetRenderText()->SetFontList(GetDefaultFontList()); 268 GetRenderText()->SetFontList(GetDefaultFontList());
268 SetBorder(std::unique_ptr<Border>(new FocusableBorder())); 269 View::SetBorder(std::unique_ptr<Border>(new FocusableBorder()));
269 SetFocusBehavior(FocusBehavior::ALWAYS); 270 SetFocusBehavior(FocusBehavior::ALWAYS);
270 271
271 // These allow BrowserView to pass edit commands from the Chrome menu to us 272 // These allow BrowserView to pass edit commands from the Chrome menu to us
272 // when we're focused by simply asking the FocusManager to 273 // when we're focused by simply asking the FocusManager to
273 // ProcessAccelerator() with the relevant accelerators. 274 // ProcessAccelerator() with the relevant accelerators.
274 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN)); 275 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN));
275 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN)); 276 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN));
276 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN)); 277 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN));
277 } 278 }
278 279
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 gfx::Size Textfield::GetPreferredSize() const { 552 gfx::Size Textfield::GetPreferredSize() const {
552 const gfx::Insets& insets = GetInsets(); 553 const gfx::Insets& insets = GetInsets();
553 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) + 554 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) +
554 insets.width(), GetFontList().GetHeight() + insets.height()); 555 insets.width(), GetFontList().GetHeight() + insets.height());
555 } 556 }
556 557
557 const char* Textfield::GetClassName() const { 558 const char* Textfield::GetClassName() const {
558 return kViewClassName; 559 return kViewClassName;
559 } 560 }
560 561
562 void Textfield::SetBorder(std::unique_ptr<Border> b) {
563 use_focus_ring_ = false;
564 View::SetBorder(std::move(b));
sky 2016/10/07 03:10:48 Should you also call FocusRing::Uninstall?
Evan Stade 2016/10/10 17:08:28 I didn't add that because it's dead code, but if y
sky 2016/10/10 19:55:19 Can you clarify what you mean by dead code? If the
565 }
566
561 gfx::NativeCursor Textfield::GetCursor(const ui::MouseEvent& event) { 567 gfx::NativeCursor Textfield::GetCursor(const ui::MouseEvent& event) {
562 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); 568 bool in_selection = GetRenderText()->IsPointInSelection(event.location());
563 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; 569 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED;
564 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection); 570 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection);
565 return text_cursor ? GetNativeIBeamCursor() : gfx::kNullCursor; 571 return text_cursor ? GetNativeIBeamCursor() : gfx::kNullCursor;
566 } 572 }
567 573
568 bool Textfield::OnMousePressed(const ui::MouseEvent& event) { 574 bool Textfield::OnMousePressed(const ui::MouseEvent& event) {
569 TrackMouseClicks(event); 575 TrackMouseClicks(event);
570 576
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 void Textfield::OnPaint(gfx::Canvas* canvas) { 986 void Textfield::OnPaint(gfx::Canvas* canvas) {
981 OnPaintBackground(canvas); 987 OnPaintBackground(canvas);
982 PaintTextAndCursor(canvas); 988 PaintTextAndCursor(canvas);
983 OnPaintBorder(canvas); 989 OnPaintBorder(canvas);
984 } 990 }
985 991
986 void Textfield::OnFocus() { 992 void Textfield::OnFocus() {
987 GetRenderText()->set_focused(true); 993 GetRenderText()->set_focused(true);
988 if (ShouldShowCursor()) 994 if (ShouldShowCursor())
989 GetRenderText()->set_cursor_visible(true); 995 GetRenderText()->set_cursor_visible(true);
990 SchedulePaint();
991 if (GetInputMethod()) 996 if (GetInputMethod())
992 GetInputMethod()->SetFocusedTextInputClient(this); 997 GetInputMethod()->SetFocusedTextInputClient(this);
993 OnCaretBoundsChanged(); 998 OnCaretBoundsChanged();
994 if (ShouldBlinkCursor()) 999 if (ShouldBlinkCursor())
995 StartBlinkingCursor(); 1000 StartBlinkingCursor();
1001 if (use_focus_ring_)
1002 FocusRing::Install(this);
1003 SchedulePaint();
996 View::OnFocus(); 1004 View::OnFocus();
997 SchedulePaint();
998 if (ui::MaterialDesignController::IsSecondaryUiMaterial())
999 FocusRing::Install(this);
1000 } 1005 }
1001 1006
1002 void Textfield::OnBlur() { 1007 void Textfield::OnBlur() {
1003 gfx::RenderText* render_text = GetRenderText(); 1008 gfx::RenderText* render_text = GetRenderText();
1004 render_text->set_focused(false); 1009 render_text->set_focused(false);
1005 if (GetInputMethod()) 1010 if (GetInputMethod())
1006 GetInputMethod()->DetachTextInputClient(this); 1011 GetInputMethod()->DetachTextInputClient(this);
1007 StopBlinkingCursor(); 1012 StopBlinkingCursor();
1008 if (render_text->cursor_visible()) { 1013 if (render_text->cursor_visible()) {
1009 render_text->set_cursor_visible(false); 1014 render_text->set_cursor_visible(false);
1010 RepaintCursor(); 1015 RepaintCursor();
1011 } 1016 }
1012 1017
1013 DestroyTouchSelection(); 1018 DestroyTouchSelection();
1014 1019
1015 // Border typically draws focus indicator. 1020 if (use_focus_ring_)
1021 FocusRing::Uninstall(this);
1016 SchedulePaint(); 1022 SchedulePaint();
1017 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) 1023 View::OnBlur();
1018 FocusRing::Uninstall(this);
1019 } 1024 }
1020 1025
1021 gfx::Point Textfield::GetKeyboardContextMenuLocation() { 1026 gfx::Point Textfield::GetKeyboardContextMenuLocation() {
1022 return GetCaretBounds().bottom_right(); 1027 return GetCaretBounds().bottom_right();
1023 } 1028 }
1024 1029
1025 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { 1030 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) {
1026 gfx::RenderText* render_text = GetRenderText(); 1031 gfx::RenderText* render_text = GetRenderText();
1027 render_text->SetColor(GetTextColor()); 1032 render_text->SetColor(GetTextColor());
1028 UpdateBackgroundColor(); 1033 UpdateBackgroundColor();
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 } 2083 }
2079 2084
2080 void Textfield::OnCursorBlinkTimerFired() { 2085 void Textfield::OnCursorBlinkTimerFired() {
2081 DCHECK(ShouldBlinkCursor()); 2086 DCHECK(ShouldBlinkCursor());
2082 gfx::RenderText* render_text = GetRenderText(); 2087 gfx::RenderText* render_text = GetRenderText();
2083 render_text->set_cursor_visible(!render_text->cursor_visible()); 2088 render_text->set_cursor_visible(!render_text->cursor_visible());
2084 RepaintCursor(); 2089 RepaintCursor();
2085 } 2090 }
2086 2091
2087 } // namespace views 2092 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698