Chromium Code Reviews| Index: ui/views/controls/label.h |
| diff --git a/ui/views/controls/label.h b/ui/views/controls/label.h |
| index 450716ac1088b97707898e3849536fd4d1b3916b..81aa058d36ce4e857f2712e13c099920616a4674 100644 |
| --- a/ui/views/controls/label.h |
| +++ b/ui/views/controls/label.h |
| @@ -8,16 +8,22 @@ |
| #include "base/compiler_specific.h" |
| #include "base/gtest_prod_util.h" |
| #include "base/macros.h" |
| +#include "ui/base/models/simple_menu_model.h" |
| #include "ui/gfx/render_text.h" |
| +#include "ui/views/context_menu_controller.h" |
| #include "ui/views/selection_controller_delegate.h" |
| #include "ui/views/view.h" |
| namespace views { |
| class LabelSelectionTest; |
| +class MenuRunner; |
| class SelectionController; |
| // A view subclass that can display a string. |
| -class VIEWS_EXPORT Label : public View, public SelectionControllerDelegate { |
| +class VIEWS_EXPORT Label : public View, |
| + public ContextMenuController, |
| + public SelectionControllerDelegate, |
| + public ui::SimpleMenuModel::Delegate { |
| public: |
| // Internal class name. |
| static const char kViewClassName[]; |
| @@ -208,6 +214,9 @@ class VIEWS_EXPORT Label : public View, public SelectionControllerDelegate { |
| bool OnMouseDragged(const ui::MouseEvent& event) override; |
| void OnMouseReleased(const ui::MouseEvent& event) override; |
| void OnMouseCaptureLost() override; |
| + bool OnKeyPressed(const ui::KeyEvent& event) override; |
| + bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
| + bool CanHandleAccelerators() const override; |
| private: |
| FRIEND_TEST_ALL_PREFIXES(LabelTest, ResetRenderTextData); |
| @@ -216,8 +225,14 @@ class VIEWS_EXPORT Label : public View, public SelectionControllerDelegate { |
| FRIEND_TEST_ALL_PREFIXES(LabelTest, EmptyLabel); |
| FRIEND_TEST_ALL_PREFIXES(LabelTest, FocusBounds); |
| FRIEND_TEST_ALL_PREFIXES(LabelTest, MultiLineSizingWithElide); |
| + FRIEND_TEST_ALL_PREFIXES(LabelSelectionTest, ContextMenuContents); |
|
msw
2016/11/15 20:06:45
Can we avoid this and add any needed helpers on La
karandeepb
2016/11/16 07:48:29
Done.
|
| friend class LabelSelectionTest; |
| + // ContextMenuController overrides: |
| + void ShowContextMenuForView(View* source, |
| + const gfx::Point& point, |
| + ui::MenuSourceType source_type) override; |
| + |
| // SelectionControllerDelegate overrides: |
| gfx::RenderText* GetRenderTextForSelectionController() override; |
| bool IsReadOnly() const override; |
| @@ -232,6 +247,13 @@ class VIEWS_EXPORT Label : public View, public SelectionControllerDelegate { |
| bool PasteSelectionClipboard() override; |
| void UpdateSelectionClipboard() override; |
| + // ui::SimpleMenuModel::Delegate overrides: |
| + bool IsCommandIdChecked(int command_id) const override; |
| + bool IsCommandIdEnabled(int command_id) const override; |
| + void ExecuteCommand(int command_id, int event_flags) override; |
| + bool GetAcceleratorForCommandId(int command_id, |
| + ui::Accelerator* accelerator) const override; |
| + |
| const gfx::RenderText* GetRenderTextForSelectionController() const; |
| void Init(const base::string16& text, const gfx::FontList& font_list); |
| @@ -263,6 +285,15 @@ class VIEWS_EXPORT Label : public View, public SelectionControllerDelegate { |
| // Empties |lines_| and updates |stored_selection_range_|. |
| void ClearRenderTextLines() const; |
| + // Returns the currently selected text. |
| + base::string16 GetSelectedText() const; |
| + |
| + // Updates the clipboard with the currently selected text. |
| + void CopyToClipboard(); |
| + |
| + // Builds |context_menu_contents_|. |
| + void BuildContextMenuContents(); |
| + |
| // An un-elided and single-line RenderText object used for preferred sizing. |
| std::unique_ptr<gfx::RenderText> render_text_; |
| @@ -309,6 +340,10 @@ class VIEWS_EXPORT Label : public View, public SelectionControllerDelegate { |
| std::unique_ptr<SelectionController> selection_controller_; |
| + // Context menu related members. |
| + ui::SimpleMenuModel context_menu_contents_; |
| + std::unique_ptr<views::MenuRunner> context_menu_runner_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(Label); |
| }; |