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/label.h" | 5 #include "ui/views/controls/label.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 | 634 |
635 context_menu_runner_.reset( | 635 context_menu_runner_.reset( |
636 new MenuRunner(&context_menu_contents_, MenuRunner::HAS_MNEMONICS | | 636 new MenuRunner(&context_menu_contents_, MenuRunner::HAS_MNEMONICS | |
637 MenuRunner::CONTEXT_MENU | | 637 MenuRunner::CONTEXT_MENU | |
638 MenuRunner::ASYNC)); | 638 MenuRunner::ASYNC)); |
639 ignore_result(context_menu_runner_->RunMenuAt( | 639 ignore_result(context_menu_runner_->RunMenuAt( |
640 GetWidget(), nullptr, gfx::Rect(point, gfx::Size()), MENU_ANCHOR_TOPLEFT, | 640 GetWidget(), nullptr, gfx::Rect(point, gfx::Size()), MENU_ANCHOR_TOPLEFT, |
641 source_type)); | 641 source_type)); |
642 } | 642 } |
643 | 643 |
644 bool Label::GetDecoratedWordAtPoint(const gfx::Point& point, | 644 bool Label::GetDecoratedWordAndBaselineAtPoint( |
645 gfx::DecoratedText* decorated_word, | 645 const gfx::Point& point, |
646 gfx::Point* baseline_point) { | 646 gfx::DecoratedText* decorated_word, |
| 647 gfx::Point* baseline_point) { |
647 gfx::RenderText* render_text = GetRenderTextForSelectionController(); | 648 gfx::RenderText* render_text = GetRenderTextForSelectionController(); |
648 return render_text | 649 return render_text |
649 ? render_text->GetDecoratedWordAtPoint(point, decorated_word, | 650 ? render_text->GetDecoratedWordAndBaselineAtPoint( |
650 baseline_point) | 651 point, decorated_word, baseline_point) |
651 : false; | 652 : false; |
652 } | 653 } |
653 | 654 |
| 655 bool Label::GetDecoratedTextAndBaselineFromSelection( |
| 656 gfx::DecoratedText* decorated_text, |
| 657 gfx::Point* baseline_point) { |
| 658 if (!selectable()) |
| 659 return false; |
| 660 |
| 661 gfx::RenderText* render_text = GetRenderTextForSelectionController(); |
| 662 if (!render_text) |
| 663 return false; |
| 664 |
| 665 return render_text->GetDecoratedTextAndBaselineForRange( |
| 666 render_text->selection(), decorated_text, baseline_point); |
| 667 } |
| 668 |
654 gfx::RenderText* Label::GetRenderTextForSelectionController() { | 669 gfx::RenderText* Label::GetRenderTextForSelectionController() { |
655 return const_cast<gfx::RenderText*>( | 670 return const_cast<gfx::RenderText*>( |
656 static_cast<const Label*>(this)->GetRenderTextForSelectionController()); | 671 static_cast<const Label*>(this)->GetRenderTextForSelectionController()); |
657 } | 672 } |
658 | 673 |
659 bool Label::IsReadOnly() const { | 674 bool Label::IsReadOnly() const { |
660 return true; | 675 return true; |
661 } | 676 } |
662 | 677 |
663 bool Label::SupportsDrag() const { | 678 bool Label::SupportsDrag() const { |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 .WriteText(GetSelectedText()); | 1047 .WriteText(GetSelectedText()); |
1033 } | 1048 } |
1034 | 1049 |
1035 void Label::BuildContextMenuContents() { | 1050 void Label::BuildContextMenuContents() { |
1036 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1051 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
1037 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, | 1052 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, |
1038 IDS_APP_SELECT_ALL); | 1053 IDS_APP_SELECT_ALL); |
1039 } | 1054 } |
1040 | 1055 |
1041 } // namespace views | 1056 } // namespace views |
OLD | NEW |