Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Unified Diff: ui/views/controls/label.h

Issue 2422993002: views::Label: Implement context menu, keyboard shortcuts for copy/select all. (Closed)
Patch Set: Address comments. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | ui/views/controls/label.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/label.h
diff --git a/ui/views/controls/label.h b/ui/views/controls/label.h
index 450716ac1088b97707898e3849536fd4d1b3916b..fbf67e796294c8e95a6197d065895f611c6cc91b 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[];
@@ -145,7 +151,8 @@ class VIEWS_EXPORT Label : public View, public SelectionControllerDelegate {
bool selectable() const { return !!selection_controller_; }
// Sets whether the label is selectable. False is returned if the call fails,
- // i.e. when selection is not supported but |selectable| is true.
+ // i.e. when selection is not supported but |selectable| is true. For example,
+ // obscured labels do not support text selection.
bool SetSelectable(bool selectable);
// Returns true if the label has a selection.
@@ -208,6 +215,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);
@@ -218,6 +228,11 @@ class VIEWS_EXPORT Label : public View, public SelectionControllerDelegate {
FRIEND_TEST_ALL_PREFIXES(LabelTest, MultiLineSizingWithElide);
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);
};
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | ui/views/controls/label.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698