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

Side by Side Diff: ui/views/controls/label.h

Issue 2422993002: views::Label: Implement context menu, keyboard shortcuts for copy/select all. (Closed)
Patch Set: -- 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 unified diff | Download patch
OLDNEW
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 LabelTest; 18 class LabelTest;
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 {
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.
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
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 AcceleratorPressed(const ui::Accelerator& accelerator) override;
218 bool CanHandleAccelerators() const override;
219 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
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);
219 friend class LabelTest; 228 friend class LabelTest;
220 229
230 // 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.
231 bool IsCommandIdChecked(int command_id) const override;
232 bool IsCommandIdEnabled(int command_id) const override;
233 void ExecuteCommand(int command_id, int event_flags) override;
234 bool GetAcceleratorForCommandId(int command_id,
235 ui::Accelerator* accelerator) const override;
236
237 // ContextMenuController overrides:
238 void ShowContextMenuForView(View* source,
239 const gfx::Point& point,
240 ui::MenuSourceType source_type) override;
241
221 // SelectionControllerDelegate overrides: 242 // SelectionControllerDelegate overrides:
222 gfx::RenderText* GetRenderTextForSelectionController() override; 243 gfx::RenderText* GetRenderTextForSelectionController() override;
223 bool IsReadOnly() const override; 244 bool IsReadOnly() const override;
224 bool SupportsDrag() const override; 245 bool SupportsDrag() const override;
225 bool HasTextBeingDragged() const override; 246 bool HasTextBeingDragged() const override;
226 void SetTextBeingDragged(bool value) override; 247 void SetTextBeingDragged(bool value) override;
227 int GetViewHeight() const override; 248 int GetViewHeight() const override;
228 int GetViewWidth() const override; 249 int GetViewWidth() const override;
229 int GetDragSelectionDelay() const override; 250 int GetDragSelectionDelay() const override;
230 void OnBeforePointerAction() override; 251 void OnBeforePointerAction() override;
(...skipping 25 matching lines...) Expand all
256 void ApplyTextColors() const; 277 void ApplyTextColors() const;
257 278
258 // Updates any colors that have not been explicitly set from the theme. 279 // Updates any colors that have not been explicitly set from the theme.
259 void UpdateColorsFromTheme(const ui::NativeTheme* theme); 280 void UpdateColorsFromTheme(const ui::NativeTheme* theme);
260 281
261 bool ShouldShowDefaultTooltip() const; 282 bool ShouldShowDefaultTooltip() const;
262 283
263 // Empties |lines_| and updates |stored_selection_range_|. 284 // Empties |lines_| and updates |stored_selection_range_|.
264 void ClearRenderTextLines() const; 285 void ClearRenderTextLines() const;
265 286
287 // Returns the currently selected text.
288 base::string16 GetSelectedText() const;
289
290 // Updates the clipboard with the currently selected text.
291 void CopyToClipboard();
292
293 // Builds |context_menu_contents_|.
294 void BuildContextMenuContents();
295
266 // An un-elided and single-line RenderText object used for preferred sizing. 296 // An un-elided and single-line RenderText object used for preferred sizing.
267 std::unique_ptr<gfx::RenderText> render_text_; 297 std::unique_ptr<gfx::RenderText> render_text_;
268 298
269 // The RenderText instances used to display elided and multi-line text. 299 // The RenderText instances used to display elided and multi-line text.
270 mutable std::vector<std::unique_ptr<gfx::RenderText>> lines_; 300 mutable std::vector<std::unique_ptr<gfx::RenderText>> lines_;
271 301
272 // Persists the current selection range between the calls to 302 // Persists the current selection range between the calls to
273 // ClearRenderTextLines() and MaybeBuildRenderTextLines(). Holds an 303 // ClearRenderTextLines() and MaybeBuildRenderTextLines(). Holds an
274 // InvalidRange when not in use. 304 // InvalidRange when not in use.
275 mutable gfx::Range stored_selection_range_; 305 mutable gfx::Range stored_selection_range_;
(...skipping 26 matching lines...) Expand all
302 bool collapse_when_hidden_; 332 bool collapse_when_hidden_;
303 int fixed_width_; 333 int fixed_width_;
304 int max_width_; 334 int max_width_;
305 335
306 // TODO(ckocagil): Remove is_first_paint_text_ before crbug.com/441028 is 336 // TODO(ckocagil): Remove is_first_paint_text_ before crbug.com/441028 is
307 // closed. 337 // closed.
308 bool is_first_paint_text_; 338 bool is_first_paint_text_;
309 339
310 std::unique_ptr<SelectionController> selection_controller_; 340 std::unique_ptr<SelectionController> selection_controller_;
311 341
342 // Context menu related members.
343 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.
344 std::unique_ptr<views::MenuRunner> context_menu_runner_;
345
312 DISALLOW_COPY_AND_ASSIGN(Label); 346 DISALLOW_COPY_AND_ASSIGN(Label);
313 }; 347 };
314 348
315 } // namespace views 349 } // namespace views
316 350
317 #endif // UI_VIEWS_CONTROLS_LABEL_H_ 351 #endif // UI_VIEWS_CONTROLS_LABEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698