| Index: ui/views/controls/label.h
|
| diff --git a/ui/views/controls/label.h b/ui/views/controls/label.h
|
| index 9421d1dc68fcad05c2434e122a395c3df2cb994f..1ef8e09ed1ee1fc811249012b69bd467786852ae 100644
|
| --- a/ui/views/controls/label.h
|
| +++ b/ui/views/controls/label.h
|
| @@ -8,13 +8,15 @@
|
| #include "base/compiler_specific.h"
|
| #include "base/gtest_prod_util.h"
|
| #include "base/macros.h"
|
| +#include "base/optional.h"
|
| #include "ui/gfx/render_text.h"
|
| +#include "ui/views/selection_controller.h"
|
| #include "ui/views/view.h"
|
|
|
| namespace views {
|
|
|
| // A view subclass that can display a string.
|
| -class VIEWS_EXPORT Label : public View {
|
| +class VIEWS_EXPORT Label : public View, SelectionController::Delegate {
|
| public:
|
| // Internal class name.
|
| static const char kViewClassName[];
|
| @@ -51,11 +53,23 @@ class VIEWS_EXPORT Label : public View {
|
|
|
| SkColor enabled_color() const { return actual_enabled_color_; }
|
|
|
| - // Sets the background color. This won't be explicitly drawn, but the label
|
| + // Sets the background color. This won't be explicitly drawn, but the label
|
| // will force the text color to be readable over it.
|
| void SetBackgroundColor(SkColor color);
|
| SkColor background_color() const { return background_color_; }
|
|
|
| + // Sets the selection text color. This will automatically force the color to
|
| + // be readable over the selection background color, if auto color readability
|
| + // is enabled. Initialized with system default.
|
| + void SetSelectionTextColor(SkColor color);
|
| + SkColor selection_text_color() const { return actual_selection_text_color_; }
|
| +
|
| + // Sets the selection background color. Initialized with system default.
|
| + void SetSelectionBackgroundColor(SkColor color);
|
| + SkColor selection_background_color() const {
|
| + return selection_background_color_;
|
| + }
|
| +
|
| // Set drop shadows underneath the text.
|
| void SetShadows(const gfx::ShadowValues& shadows);
|
| const gfx::ShadowValues& shadows() const { return render_text_->shadows(); }
|
| @@ -126,6 +140,31 @@ class VIEWS_EXPORT Label : public View {
|
| // Get the text as displayed to the user, respecting the obscured flag.
|
| base::string16 GetDisplayTextForTesting();
|
|
|
| + // Returns true if the label can be made selectable. For example, multiline
|
| + // labels do not currently support text selection.
|
| + virtual bool IsSelectionSupported() const;
|
| +
|
| + // Returns true if the label is selectable. Default is false.
|
| + bool selectable() const { return selection_controller_.get() != nullptr; }
|
| +
|
| + // Sets whether the label is selectable. False is returned if the call fails,
|
| + // i.e. when selection is not supported but |selectable| is true.
|
| + bool SetSelectable(bool selectable);
|
| +
|
| + // Returns true if the label has a selection.
|
| + // Todo(karandeepb): Make the method const.
|
| + bool HasSelection();
|
| +
|
| + // Selects the entire text. NO-OP if the label is not selectable.
|
| + void SelectAll();
|
| +
|
| + // Clears any active selection.
|
| + void ClearSelection();
|
| +
|
| + // Selects the given text range. NO-OP if the label is not selectable or the
|
| + // |range| endpoints don't lie on the grapheme boundaries.
|
| + void SelectRange(const gfx::Range& range);
|
| +
|
| // View:
|
| gfx::Insets GetInsets() const override;
|
| int GetBaseline() const override;
|
| @@ -159,6 +198,12 @@ class VIEWS_EXPORT Label : public View {
|
| void OnPaint(gfx::Canvas* canvas) override;
|
| void OnDeviceScaleFactorChanged(float device_scale_factor) override;
|
| void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
|
| + gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override;
|
| + void OnFocus() override;
|
| + void OnBlur() override;
|
| + bool OnMousePressed(const ui::MouseEvent& event) override;
|
| + bool OnMouseDragged(const ui::MouseEvent& event) override;
|
| + void OnMouseReleased(const ui::MouseEvent& event) override;
|
|
|
| private:
|
| FRIEND_TEST_ALL_PREFIXES(LabelTest, ResetRenderTextData);
|
| @@ -167,6 +212,22 @@ class VIEWS_EXPORT Label : public View {
|
| FRIEND_TEST_ALL_PREFIXES(LabelFocusTest, FocusBounds);
|
| FRIEND_TEST_ALL_PREFIXES(LabelFocusTest, EmptyLabel);
|
|
|
| + // SelectionController::Delegate overrides:
|
| + gfx::RenderText* GetRenderTextForSelection() override;
|
| + bool IsReadOnly() const override;
|
| + bool SupportsDrag() const override;
|
| + bool HasTextBeingDragged() const override;
|
| + void SetTextBeingDragged(bool value) override;
|
| + int GetViewHeight() const override;
|
| + int GetViewWidth() const override;
|
| + int GetDragSelectionDelay() const override;
|
| + void OnBeforeMouseAction() override;
|
| + void OnAfterMouseAction(bool text_changed, bool selection_changed) override;
|
| + void OnBeforeSelectionUpdated() override;
|
| + void OnAfterSelectionUpdated() override;
|
| + void PasteSelectionClipboard(const ui::MouseEvent& event) override;
|
| + void UpdateSelectionClipboard() override;
|
| +
|
| void Init(const base::string16& text, const gfx::FontList& font_list);
|
|
|
| void ResetLayout();
|
| @@ -193,22 +254,38 @@ class VIEWS_EXPORT Label : public View {
|
|
|
| bool ShouldShowDefaultTooltip() const;
|
|
|
| + // Called when the text selection is updated. NO-OP if a mouse action is in
|
| + // progress.
|
| + void OnSelectionUpdated();
|
| +
|
| + // Empties |lines_| and updates |last_selection_range_|.
|
| + void ClearLines();
|
| +
|
| // An un-elided and single-line RenderText object used for preferred sizing.
|
| std::unique_ptr<gfx::RenderText> render_text_;
|
|
|
| // The RenderText instances used to display elided and multi-line text.
|
| std::vector<std::unique_ptr<gfx::RenderText>> lines_;
|
|
|
| + // Persists the current selection range between the calls to ClearLines() and
|
| + // MaybeBuildRenderTextLines().
|
| + base::Optional<gfx::Range> last_selection_range_;
|
| +
|
| SkColor requested_enabled_color_;
|
| SkColor actual_enabled_color_;
|
| SkColor requested_disabled_color_;
|
| SkColor actual_disabled_color_;
|
| SkColor background_color_;
|
| + SkColor requested_selection_text_color_;
|
| + SkColor actual_selection_text_color_;
|
| + SkColor selection_background_color_;
|
|
|
| // Set to true once the corresponding setter is invoked.
|
| bool enabled_color_set_;
|
| bool disabled_color_set_;
|
| bool background_color_set_;
|
| + bool selection_text_color_set_;
|
| + bool selection_background_color_set_;
|
|
|
| gfx::ElideBehavior elide_behavior_;
|
|
|
| @@ -227,6 +304,12 @@ class VIEWS_EXPORT Label : public View {
|
| // closed.
|
| bool is_first_paint_text_;
|
|
|
| + // Tracks whether a mouse action is being performed i.e. OnBeforeMouseAction()
|
| + // has been called, but OnAfterMouseAction() has not yet been called.
|
| + bool performing_mouse_action_;
|
| +
|
| + std::unique_ptr<SelectionController> selection_controller_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(Label);
|
| };
|
|
|
|
|