Chromium Code Reviews| Index: ui/views/controls/label.h |
| diff --git a/ui/views/controls/label.h b/ui/views/controls/label.h |
| index df1414c3569854a61f5fa115e09055d80f639347..1aa91f2dc24a92ae05177e05bfd7a2dfc6e842bd 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 LabelTest; |
| +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 { |
|
msw
2016/11/09 18:32:53
It would be nice to use composition instead of inh
karandeepb
2016/11/15 10:54:32
It may be feasible, but since we are just implemen
msw
2016/11/15 20:06:45
Agreed, it's fine as-is for now.
|
| 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 AcceleratorPressed(const ui::Accelerator& accelerator) override; |
| + bool CanHandleAccelerators() const override; |
| + bool OnKeyPressed(const ui::KeyEvent& event) override; |
|
msw
2016/11/09 18:32:53
nit: match the order in view.h
karandeepb
2016/11/15 10:54:32
Done. Order for the existing functions wasn't corr
|
| private: |
| FRIEND_TEST_ALL_PREFIXES(LabelTest, ResetRenderTextData); |
| @@ -218,6 +227,18 @@ class VIEWS_EXPORT Label : public View, public SelectionControllerDelegate { |
| FRIEND_TEST_ALL_PREFIXES(LabelTest, MultiLineSizingWithElide); |
| friend class LabelTest; |
| + // ui::SimpleMenuModel::Delegate overrides: |
|
msw
2016/11/09 18:32:53
nit: try to keep the same order as the subclass li
karandeepb
2016/11/15 10:54:32
Done.
|
| + 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; |
| + |
| + // 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; |
| @@ -263,6 +284,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 +339,10 @@ class VIEWS_EXPORT Label : public View, public SelectionControllerDelegate { |
| std::unique_ptr<SelectionController> selection_controller_; |
| + // Context menu related members. |
| + std::unique_ptr<ui::SimpleMenuModel> context_menu_contents_; |
|
msw
2016/11/09 18:32:53
nit: avoid unique_ptr, use plain member, if possib
karandeepb
2016/11/15 10:54:32
Done.
|
| + std::unique_ptr<views::MenuRunner> context_menu_runner_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(Label); |
| }; |