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 "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 return (system_value == INFINITE) ? 0 : system_value; | 248 return (system_value == INFINITE) ? 0 : system_value; |
249 #endif | 249 #endif |
250 return default_value; | 250 return default_value; |
251 } | 251 } |
252 | 252 |
253 Textfield::Textfield() | 253 Textfield::Textfield() |
254 : model_(new TextfieldModel(this)), | 254 : model_(new TextfieldModel(this)), |
255 controller_(NULL), | 255 controller_(NULL), |
256 read_only_(false), | 256 read_only_(false), |
257 default_width_in_chars_(0), | 257 default_width_in_chars_(0), |
| 258 use_default_text_color_(true), |
| 259 use_default_background_color_(true), |
| 260 use_default_selection_text_color_(true), |
| 261 use_default_selection_background_color_(true), |
258 text_color_(SK_ColorBLACK), | 262 text_color_(SK_ColorBLACK), |
259 use_default_text_color_(true), | |
260 background_color_(SK_ColorWHITE), | 263 background_color_(SK_ColorWHITE), |
261 use_default_background_color_(true), | 264 selection_text_color_(SK_ColorWHITE), |
| 265 selection_background_color_(SK_ColorBLUE), |
262 placeholder_text_color_(kDefaultPlaceholderTextColor), | 266 placeholder_text_color_(kDefaultPlaceholderTextColor), |
263 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), | 267 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), |
264 performing_user_action_(false), | 268 performing_user_action_(false), |
265 skip_input_method_cancel_composition_(false), | 269 skip_input_method_cancel_composition_(false), |
266 cursor_visible_(false), | 270 cursor_visible_(false), |
267 drop_cursor_visible_(false), | 271 drop_cursor_visible_(false), |
268 initiating_drag_(false), | 272 initiating_drag_(false), |
269 aggregated_clicks_(0), | 273 aggregated_clicks_(0), |
270 weak_ptr_factory_(this) { | 274 weak_ptr_factory_(this) { |
271 set_context_menu_controller(this); | 275 set_context_menu_controller(this); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 background_color_ = color; | 382 background_color_ = color; |
379 use_default_background_color_ = false; | 383 use_default_background_color_ = false; |
380 UpdateBackgroundColor(); | 384 UpdateBackgroundColor(); |
381 } | 385 } |
382 | 386 |
383 void Textfield::UseDefaultBackgroundColor() { | 387 void Textfield::UseDefaultBackgroundColor() { |
384 use_default_background_color_ = true; | 388 use_default_background_color_ = true; |
385 UpdateBackgroundColor(); | 389 UpdateBackgroundColor(); |
386 } | 390 } |
387 | 391 |
| 392 SkColor Textfield::GetSelectionTextColor() const { |
| 393 return use_default_selection_text_color_ ? |
| 394 GetNativeTheme()->GetSystemColor( |
| 395 ui::NativeTheme::kColorId_TextfieldSelectionColor) : |
| 396 selection_text_color_; |
| 397 } |
| 398 |
| 399 void Textfield::SetSelectionTextColor(SkColor color) { |
| 400 selection_text_color_ = color; |
| 401 use_default_selection_text_color_ = false; |
| 402 GetRenderText()->set_selection_color(GetSelectionTextColor()); |
| 403 SchedulePaint(); |
| 404 } |
| 405 |
| 406 void Textfield::UseDefaultSelectionTextColor() { |
| 407 use_default_selection_text_color_ = true; |
| 408 GetRenderText()->set_selection_color(GetSelectionTextColor()); |
| 409 SchedulePaint(); |
| 410 } |
| 411 |
| 412 SkColor Textfield::GetSelectionBackgroundColor() const { |
| 413 return use_default_selection_background_color_ ? |
| 414 GetNativeTheme()->GetSystemColor( |
| 415 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused) : |
| 416 selection_background_color_; |
| 417 } |
| 418 |
| 419 void Textfield::SetSelectionBackgroundColor(SkColor color) { |
| 420 selection_background_color_ = color; |
| 421 use_default_selection_background_color_ = false; |
| 422 GetRenderText()->set_selection_background_focused_color( |
| 423 GetSelectionBackgroundColor()); |
| 424 SchedulePaint(); |
| 425 } |
| 426 |
| 427 void Textfield::UseDefaultSelectionBackgroundColor() { |
| 428 use_default_selection_background_color_ = true; |
| 429 GetRenderText()->set_selection_background_focused_color( |
| 430 GetSelectionBackgroundColor()); |
| 431 SchedulePaint(); |
| 432 } |
| 433 |
388 bool Textfield::GetCursorEnabled() const { | 434 bool Textfield::GetCursorEnabled() const { |
389 return GetRenderText()->cursor_enabled(); | 435 return GetRenderText()->cursor_enabled(); |
390 } | 436 } |
391 | 437 |
392 void Textfield::SetCursorEnabled(bool enabled) { | 438 void Textfield::SetCursorEnabled(bool enabled) { |
393 GetRenderText()->SetCursorEnabled(enabled); | 439 GetRenderText()->SetCursorEnabled(enabled); |
394 } | 440 } |
395 | 441 |
396 const gfx::FontList& Textfield::GetFontList() const { | 442 const gfx::FontList& Textfield::GetFontList() const { |
397 return GetRenderText()->font_list(); | 443 return GetRenderText()->font_list(); |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 | 947 |
902 gfx::Point Textfield::GetKeyboardContextMenuLocation() { | 948 gfx::Point Textfield::GetKeyboardContextMenuLocation() { |
903 return GetCaretBounds().bottom_right(); | 949 return GetCaretBounds().bottom_right(); |
904 } | 950 } |
905 | 951 |
906 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 952 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
907 gfx::RenderText* render_text = GetRenderText(); | 953 gfx::RenderText* render_text = GetRenderText(); |
908 render_text->SetColor(GetTextColor()); | 954 render_text->SetColor(GetTextColor()); |
909 UpdateBackgroundColor(); | 955 UpdateBackgroundColor(); |
910 render_text->set_cursor_color(GetTextColor()); | 956 render_text->set_cursor_color(GetTextColor()); |
911 render_text->set_selection_color(theme->GetSystemColor( | 957 render_text->set_selection_color(GetSelectionTextColor()); |
912 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 958 render_text->set_selection_background_focused_color( |
913 render_text->set_selection_background_focused_color(theme->GetSystemColor( | 959 GetSelectionBackgroundColor()); |
914 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)); | |
915 | |
916 } | 960 } |
917 | 961 |
918 //////////////////////////////////////////////////////////////////////////////// | 962 //////////////////////////////////////////////////////////////////////////////// |
919 // Textfield, TextfieldModel::Delegate overrides: | 963 // Textfield, TextfieldModel::Delegate overrides: |
920 | 964 |
921 void Textfield::OnCompositionTextConfirmedOrCleared() { | 965 void Textfield::OnCompositionTextConfirmedOrCleared() { |
922 if (!skip_input_method_cancel_composition_) | 966 if (!skip_input_method_cancel_composition_) |
923 GetInputMethod()->CancelComposition(this); | 967 GetInputMethod()->CancelComposition(this); |
924 } | 968 } |
925 | 969 |
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1708 const size_t length = selection_clipboard_text.length(); | 1752 const size_t length = selection_clipboard_text.length(); |
1709 range = gfx::Range(range.start() + length, range.end() + length); | 1753 range = gfx::Range(range.start() + length, range.end() + length); |
1710 } | 1754 } |
1711 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1755 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
1712 UpdateAfterChange(true, true); | 1756 UpdateAfterChange(true, true); |
1713 OnAfterUserAction(); | 1757 OnAfterUserAction(); |
1714 } | 1758 } |
1715 } | 1759 } |
1716 | 1760 |
1717 } // namespace views | 1761 } // namespace views |
OLD | NEW |