Chromium Code Reviews| 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 #ifndef UI_VIEWS_CONTROLS_LABEL_H_ | 5 #ifndef UI_VIEWS_CONTROLS_LABEL_H_ |
| 6 #define UI_VIEWS_CONTROLS_LABEL_H_ | 6 #define UI_VIEWS_CONTROLS_LABEL_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "ui/base/models/simple_menu_model.h" | |
| 11 #include "ui/gfx/render_text.h" | 12 #include "ui/gfx/render_text.h" |
| 13 #include "ui/views/context_menu_controller.h" | |
| 12 #include "ui/views/selection_controller_delegate.h" | 14 #include "ui/views/selection_controller_delegate.h" |
| 13 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
| 14 | 16 |
| 15 namespace views { | 17 namespace views { |
| 16 class LabelSelectionTest; | 18 class LabelSelectionTest; |
| 19 class MenuRunner; | |
| 17 class SelectionController; | 20 class SelectionController; |
| 18 | 21 |
| 19 // A view subclass that can display a string. | 22 // A view subclass that can display a string. |
| 20 class VIEWS_EXPORT Label : public View, public SelectionControllerDelegate { | 23 class VIEWS_EXPORT Label : public View, |
| 24 public ContextMenuController, | |
| 25 public SelectionControllerDelegate, | |
| 26 public ui::SimpleMenuModel::Delegate { | |
| 21 public: | 27 public: |
| 22 // Internal class name. | 28 // Internal class name. |
| 23 static const char kViewClassName[]; | 29 static const char kViewClassName[]; |
| 24 | 30 |
| 25 // The padding for the focus border when rendering focused text. | 31 // The padding for the focus border when rendering focused text. |
| 26 static const int kFocusBorderPadding; | 32 static const int kFocusBorderPadding; |
| 27 | 33 |
| 28 Label(); | 34 Label(); |
| 29 explicit Label(const base::string16& text); | 35 explicit Label(const base::string16& text); |
| 30 Label(const base::string16& text, const gfx::FontList& font_list); | 36 Label(const base::string16& text, const gfx::FontList& font_list); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 void OnPaint(gfx::Canvas* canvas) override; | 207 void OnPaint(gfx::Canvas* canvas) override; |
| 202 void OnDeviceScaleFactorChanged(float device_scale_factor) override; | 208 void OnDeviceScaleFactorChanged(float device_scale_factor) override; |
| 203 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 209 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 204 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; | 210 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; |
| 205 void OnFocus() override; | 211 void OnFocus() override; |
| 206 void OnBlur() override; | 212 void OnBlur() override; |
| 207 bool OnMousePressed(const ui::MouseEvent& event) override; | 213 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 208 bool OnMouseDragged(const ui::MouseEvent& event) override; | 214 bool OnMouseDragged(const ui::MouseEvent& event) override; |
| 209 void OnMouseReleased(const ui::MouseEvent& event) override; | 215 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 210 void OnMouseCaptureLost() override; | 216 void OnMouseCaptureLost() override; |
| 217 bool OnKeyPressed(const ui::KeyEvent& event) override; | |
| 218 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | |
| 219 bool CanHandleAccelerators() const override; | |
| 211 | 220 |
| 212 private: | 221 private: |
| 213 FRIEND_TEST_ALL_PREFIXES(LabelTest, ResetRenderTextData); | 222 FRIEND_TEST_ALL_PREFIXES(LabelTest, ResetRenderTextData); |
| 214 FRIEND_TEST_ALL_PREFIXES(LabelTest, MultilineSupportedRenderText); | 223 FRIEND_TEST_ALL_PREFIXES(LabelTest, MultilineSupportedRenderText); |
| 215 FRIEND_TEST_ALL_PREFIXES(LabelTest, TextChangeWithoutLayout); | 224 FRIEND_TEST_ALL_PREFIXES(LabelTest, TextChangeWithoutLayout); |
| 216 FRIEND_TEST_ALL_PREFIXES(LabelTest, EmptyLabel); | 225 FRIEND_TEST_ALL_PREFIXES(LabelTest, EmptyLabel); |
| 217 FRIEND_TEST_ALL_PREFIXES(LabelTest, FocusBounds); | 226 FRIEND_TEST_ALL_PREFIXES(LabelTest, FocusBounds); |
| 218 FRIEND_TEST_ALL_PREFIXES(LabelTest, MultiLineSizingWithElide); | 227 FRIEND_TEST_ALL_PREFIXES(LabelTest, MultiLineSizingWithElide); |
| 228 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.
| |
| 219 friend class LabelSelectionTest; | 229 friend class LabelSelectionTest; |
| 220 | 230 |
| 231 // ContextMenuController overrides: | |
| 232 void ShowContextMenuForView(View* source, | |
| 233 const gfx::Point& point, | |
| 234 ui::MenuSourceType source_type) override; | |
| 235 | |
| 221 // SelectionControllerDelegate overrides: | 236 // SelectionControllerDelegate overrides: |
| 222 gfx::RenderText* GetRenderTextForSelectionController() override; | 237 gfx::RenderText* GetRenderTextForSelectionController() override; |
| 223 bool IsReadOnly() const override; | 238 bool IsReadOnly() const override; |
| 224 bool SupportsDrag() const override; | 239 bool SupportsDrag() const override; |
| 225 bool HasTextBeingDragged() const override; | 240 bool HasTextBeingDragged() const override; |
| 226 void SetTextBeingDragged(bool value) override; | 241 void SetTextBeingDragged(bool value) override; |
| 227 int GetViewHeight() const override; | 242 int GetViewHeight() const override; |
| 228 int GetViewWidth() const override; | 243 int GetViewWidth() const override; |
| 229 int GetDragSelectionDelay() const override; | 244 int GetDragSelectionDelay() const override; |
| 230 void OnBeforePointerAction() override; | 245 void OnBeforePointerAction() override; |
| 231 void OnAfterPointerAction(bool text_changed, bool selection_changed) override; | 246 void OnAfterPointerAction(bool text_changed, bool selection_changed) override; |
| 232 bool PasteSelectionClipboard() override; | 247 bool PasteSelectionClipboard() override; |
| 233 void UpdateSelectionClipboard() override; | 248 void UpdateSelectionClipboard() override; |
| 234 | 249 |
| 250 // ui::SimpleMenuModel::Delegate overrides: | |
| 251 bool IsCommandIdChecked(int command_id) const override; | |
| 252 bool IsCommandIdEnabled(int command_id) const override; | |
| 253 void ExecuteCommand(int command_id, int event_flags) override; | |
| 254 bool GetAcceleratorForCommandId(int command_id, | |
| 255 ui::Accelerator* accelerator) const override; | |
| 256 | |
| 235 const gfx::RenderText* GetRenderTextForSelectionController() const; | 257 const gfx::RenderText* GetRenderTextForSelectionController() const; |
| 236 | 258 |
| 237 void Init(const base::string16& text, const gfx::FontList& font_list); | 259 void Init(const base::string16& text, const gfx::FontList& font_list); |
| 238 | 260 |
| 239 void ResetLayout(); | 261 void ResetLayout(); |
| 240 | 262 |
| 241 // Set up |lines_| to actually be painted. | 263 // Set up |lines_| to actually be painted. |
| 242 void MaybeBuildRenderTextLines() const; | 264 void MaybeBuildRenderTextLines() const; |
| 243 | 265 |
| 244 gfx::Rect GetFocusBounds() const; | 266 gfx::Rect GetFocusBounds() const; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 256 void ApplyTextColors() const; | 278 void ApplyTextColors() const; |
| 257 | 279 |
| 258 // Updates any colors that have not been explicitly set from the theme. | 280 // Updates any colors that have not been explicitly set from the theme. |
| 259 void UpdateColorsFromTheme(const ui::NativeTheme* theme); | 281 void UpdateColorsFromTheme(const ui::NativeTheme* theme); |
| 260 | 282 |
| 261 bool ShouldShowDefaultTooltip() const; | 283 bool ShouldShowDefaultTooltip() const; |
| 262 | 284 |
| 263 // Empties |lines_| and updates |stored_selection_range_|. | 285 // Empties |lines_| and updates |stored_selection_range_|. |
| 264 void ClearRenderTextLines() const; | 286 void ClearRenderTextLines() const; |
| 265 | 287 |
| 288 // Returns the currently selected text. | |
| 289 base::string16 GetSelectedText() const; | |
| 290 | |
| 291 // Updates the clipboard with the currently selected text. | |
| 292 void CopyToClipboard(); | |
| 293 | |
| 294 // Builds |context_menu_contents_|. | |
| 295 void BuildContextMenuContents(); | |
| 296 | |
| 266 // An un-elided and single-line RenderText object used for preferred sizing. | 297 // An un-elided and single-line RenderText object used for preferred sizing. |
| 267 std::unique_ptr<gfx::RenderText> render_text_; | 298 std::unique_ptr<gfx::RenderText> render_text_; |
| 268 | 299 |
| 269 // The RenderText instances used to display elided and multi-line text. | 300 // The RenderText instances used to display elided and multi-line text. |
| 270 mutable std::vector<std::unique_ptr<gfx::RenderText>> lines_; | 301 mutable std::vector<std::unique_ptr<gfx::RenderText>> lines_; |
| 271 | 302 |
| 272 // Persists the current selection range between the calls to | 303 // Persists the current selection range between the calls to |
| 273 // ClearRenderTextLines() and MaybeBuildRenderTextLines(). Holds an | 304 // ClearRenderTextLines() and MaybeBuildRenderTextLines(). Holds an |
| 274 // InvalidRange when not in use. | 305 // InvalidRange when not in use. |
| 275 mutable gfx::Range stored_selection_range_; | 306 mutable gfx::Range stored_selection_range_; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 302 bool collapse_when_hidden_; | 333 bool collapse_when_hidden_; |
| 303 int fixed_width_; | 334 int fixed_width_; |
| 304 int max_width_; | 335 int max_width_; |
| 305 | 336 |
| 306 // TODO(ckocagil): Remove is_first_paint_text_ before crbug.com/441028 is | 337 // TODO(ckocagil): Remove is_first_paint_text_ before crbug.com/441028 is |
| 307 // closed. | 338 // closed. |
| 308 bool is_first_paint_text_; | 339 bool is_first_paint_text_; |
| 309 | 340 |
| 310 std::unique_ptr<SelectionController> selection_controller_; | 341 std::unique_ptr<SelectionController> selection_controller_; |
| 311 | 342 |
| 343 // Context menu related members. | |
| 344 ui::SimpleMenuModel context_menu_contents_; | |
| 345 std::unique_ptr<views::MenuRunner> context_menu_runner_; | |
| 346 | |
| 312 DISALLOW_COPY_AND_ASSIGN(Label); | 347 DISALLOW_COPY_AND_ASSIGN(Label); |
| 313 }; | 348 }; |
| 314 | 349 |
| 315 } // namespace views | 350 } // namespace views |
| 316 | 351 |
| 317 #endif // UI_VIEWS_CONTROLS_LABEL_H_ | 352 #endif // UI_VIEWS_CONTROLS_LABEL_H_ |
| OLD | NEW |