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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 GetRenderText()->set_selection_color(GetSelectionTextColor()); | 402 GetRenderText()->set_selection_color(GetSelectionTextColor()); |
403 SchedulePaint(); | 403 SchedulePaint(); |
404 } | 404 } |
405 | 405 |
406 void Textfield::UseDefaultSelectionTextColor() { | 406 void Textfield::UseDefaultSelectionTextColor() { |
407 use_default_selection_text_color_ = true; | 407 use_default_selection_text_color_ = true; |
408 GetRenderText()->set_selection_color(GetSelectionTextColor()); | 408 GetRenderText()->set_selection_color(GetSelectionTextColor()); |
409 SchedulePaint(); | 409 SchedulePaint(); |
410 } | 410 } |
411 | 411 |
412 void Textfield::SetShadows(const gfx::ShadowValues& shadows) { | |
413 shadows_ = shadows; | |
msw
2014/07/03 05:28:55
Just set the shadows on the RenderText here, you d
Nina
2014/07/04 13:56:48
Done.
| |
414 SchedulePaint(); | |
415 } | |
416 | |
412 SkColor Textfield::GetSelectionBackgroundColor() const { | 417 SkColor Textfield::GetSelectionBackgroundColor() const { |
413 return use_default_selection_background_color_ ? | 418 return use_default_selection_background_color_ ? |
414 GetNativeTheme()->GetSystemColor( | 419 GetNativeTheme()->GetSystemColor( |
415 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused) : | 420 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused) : |
416 selection_background_color_; | 421 selection_background_color_; |
417 } | 422 } |
418 | 423 |
419 void Textfield::SetSelectionBackgroundColor(SkColor color) { | 424 void Textfield::SetSelectionBackgroundColor(SkColor color) { |
420 selection_background_color_ = color; | 425 selection_background_color_ = color; |
421 use_default_selection_background_color_ = false; | 426 use_default_selection_background_color_ = false; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 | 599 |
595 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 600 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
596 if (event.IsOnlyMiddleMouseButton()) { | 601 if (event.IsOnlyMiddleMouseButton()) { |
597 if (GetRenderText()->IsPointInSelection(event.location())) { | 602 if (GetRenderText()->IsPointInSelection(event.location())) { |
598 OnBeforeUserAction(); | 603 OnBeforeUserAction(); |
599 ClearSelection(); | 604 ClearSelection(); |
600 ui::ScopedClipboardWriter( | 605 ui::ScopedClipboardWriter( |
601 ui::Clipboard::GetForCurrentThread(), | 606 ui::Clipboard::GetForCurrentThread(), |
602 ui::CLIPBOARD_TYPE_SELECTION).WriteText(base::string16()); | 607 ui::CLIPBOARD_TYPE_SELECTION).WriteText(base::string16()); |
603 OnAfterUserAction(); | 608 OnAfterUserAction(); |
604 } else if(!read_only()) { | 609 } else if (!read_only()) { |
605 PasteSelectionClipboard(event); | 610 PasteSelectionClipboard(event); |
606 } | 611 } |
607 } | 612 } |
608 #endif | 613 #endif |
609 } | 614 } |
610 | 615 |
611 return true; | 616 return true; |
612 } | 617 } |
613 | 618 |
614 bool Textfield::OnMouseDragged(const ui::MouseEvent& event) { | 619 bool Textfield::OnMouseDragged(const ui::MouseEvent& event) { |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1581 // Draw placeholder text if needed. | 1586 // Draw placeholder text if needed. |
1582 gfx::RenderText* render_text = GetRenderText(); | 1587 gfx::RenderText* render_text = GetRenderText(); |
1583 if (text().empty() && !GetPlaceholderText().empty()) { | 1588 if (text().empty() && !GetPlaceholderText().empty()) { |
1584 canvas->DrawStringRect(GetPlaceholderText(), GetFontList(), | 1589 canvas->DrawStringRect(GetPlaceholderText(), GetFontList(), |
1585 placeholder_text_color(), render_text->display_rect()); | 1590 placeholder_text_color(), render_text->display_rect()); |
1586 } | 1591 } |
1587 | 1592 |
1588 // Draw the text, cursor, and selection. | 1593 // Draw the text, cursor, and selection. |
1589 render_text->set_cursor_visible(cursor_visible_ && !drop_cursor_visible_ && | 1594 render_text->set_cursor_visible(cursor_visible_ && !drop_cursor_visible_ && |
1590 !HasSelection()); | 1595 !HasSelection()); |
1596 render_text->set_shadows(shadows_); | |
1597 | |
1591 render_text->Draw(canvas); | 1598 render_text->Draw(canvas); |
1592 | 1599 |
1593 // Draw the detached drop cursor that marks where the text will be dropped. | 1600 // Draw the detached drop cursor that marks where the text will be dropped. |
1594 if (drop_cursor_visible_) | 1601 if (drop_cursor_visible_) |
1595 render_text->DrawCursor(canvas, drop_cursor_position_); | 1602 render_text->DrawCursor(canvas, drop_cursor_position_); |
1596 | 1603 |
1597 canvas->Restore(); | 1604 canvas->Restore(); |
1598 } | 1605 } |
1599 | 1606 |
1600 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) { | 1607 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1761 const size_t length = selection_clipboard_text.length(); | 1768 const size_t length = selection_clipboard_text.length(); |
1762 range = gfx::Range(range.start() + length, range.end() + length); | 1769 range = gfx::Range(range.start() + length, range.end() + length); |
1763 } | 1770 } |
1764 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1771 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
1765 UpdateAfterChange(true, true); | 1772 UpdateAfterChange(true, true); |
1766 OnAfterUserAction(); | 1773 OnAfterUserAction(); |
1767 } | 1774 } |
1768 } | 1775 } |
1769 | 1776 |
1770 } // namespace views | 1777 } // namespace views |
OLD | NEW |