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

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

Issue 2810403002: Views: Don't add insets for views::Link focus rings under MD. (Closed)
Patch Set: Add missing // namespace comments Created 3 years, 8 months 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
« no previous file with comments | « chrome/browser/ui/views/harmony/layout_provider_unittest.cc ('k') | ui/views/controls/label.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 13 matching lines...) Expand all
24 // A view subclass that can display a string. 24 // A view subclass that can display a string.
25 class VIEWS_EXPORT Label : public View, 25 class VIEWS_EXPORT Label : public View,
26 public ContextMenuController, 26 public ContextMenuController,
27 public WordLookupClient, 27 public WordLookupClient,
28 public SelectionControllerDelegate, 28 public SelectionControllerDelegate,
29 public ui::SimpleMenuModel::Delegate { 29 public ui::SimpleMenuModel::Delegate {
30 public: 30 public:
31 // Internal class name. 31 // Internal class name.
32 static const char kViewClassName[]; 32 static const char kViewClassName[];
33 33
34 // The padding for the focus border when rendering focused text.
35 static const int kFocusBorderPadding;
36
37 // Helper to construct a Label that doesn't use the views typography spec. 34 // Helper to construct a Label that doesn't use the views typography spec.
38 // Using this causes Label to obtain colors from ui::NativeTheme and line 35 // Using this causes Label to obtain colors from ui::NativeTheme and line
39 // spacing from gfx::FontList::GetHeight(). 36 // spacing from gfx::FontList::GetHeight().
40 // TODO(tapted): Audit users of this class when MD is default. Then add 37 // TODO(tapted): Audit users of this class when MD is default. Then add
41 // foreground/background colors, line spacing and everything else that 38 // foreground/background colors, line spacing and everything else that
42 // views::TextContext abstracts away so the separate setters can be removed. 39 // views::TextContext abstracts away so the separate setters can be removed.
43 struct CustomFont { 40 struct CustomFont {
44 // TODO(tapted): Change this to a size delta and font weight since that's 41 // TODO(tapted): Change this to a size delta and font weight since that's
45 // typically all the callers really care about, and would allow Label to 42 // typically all the callers really care about, and would allow Label to
46 // guarantee caching of the FontList in ResourceBundle. 43 // guarantee caching of the FontList in ResourceBundle.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 void SelectAll(); 196 void SelectAll();
200 197
201 // Clears any active selection. 198 // Clears any active selection.
202 void ClearSelection(); 199 void ClearSelection();
203 200
204 // Selects the given text range. NO-OP if the label is not selectable or the 201 // Selects the given text range. NO-OP if the label is not selectable or the
205 // |range| endpoints don't lie on grapheme boundaries. 202 // |range| endpoints don't lie on grapheme boundaries.
206 void SelectRange(const gfx::Range& range); 203 void SelectRange(const gfx::Range& range);
207 204
208 // View: 205 // View:
209 gfx::Insets GetInsets() const override;
210 int GetBaseline() const override; 206 int GetBaseline() const override;
211 gfx::Size GetPreferredSize() const override; 207 gfx::Size GetPreferredSize() const override;
212 gfx::Size GetMinimumSize() const override; 208 gfx::Size GetMinimumSize() const override;
213 int GetHeightForWidth(int w) const override; 209 int GetHeightForWidth(int w) const override;
214 void Layout() override; 210 void Layout() override;
215 const char* GetClassName() const override; 211 const char* GetClassName() const override;
216 View* GetTooltipHandlerForPoint(const gfx::Point& point) override; 212 View* GetTooltipHandlerForPoint(const gfx::Point& point) override;
217 bool CanProcessEventsWithinSubtree() const override; 213 bool CanProcessEventsWithinSubtree() const override;
218 WordLookupClient* GetWordLookupClient() override; 214 WordLookupClient* GetWordLookupClient() override;
219 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; 215 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
220 bool GetTooltipText(const gfx::Point& p, 216 bool GetTooltipText(const gfx::Point& p,
221 base::string16* tooltip) const override; 217 base::string16* tooltip) const override;
222 void OnEnabledChanged() override; 218 void OnEnabledChanged() override;
223 219
224 protected: 220 protected:
225 // Create a single RenderText instance to actually be painted. 221 // Create a single RenderText instance to actually be painted.
226 virtual std::unique_ptr<gfx::RenderText> CreateRenderText( 222 virtual std::unique_ptr<gfx::RenderText> CreateRenderText(
227 const base::string16& text, 223 const base::string16& text,
228 gfx::HorizontalAlignment alignment, 224 gfx::HorizontalAlignment alignment,
229 gfx::DirectionalityMode directionality, 225 gfx::DirectionalityMode directionality,
230 gfx::ElideBehavior elide_behavior) const; 226 gfx::ElideBehavior elide_behavior) const;
231 227
228 // Draw a focus ring. The default implementation does nothing.
229 virtual void PaintFocusRing(gfx::Canvas* canvas) const;
230 gfx::Rect GetFocusRingBounds() const;
231
232 void PaintText(gfx::Canvas* canvas); 232 void PaintText(gfx::Canvas* canvas);
233 233
234 // View: 234 // View:
235 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; 235 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
236 void VisibilityChanged(View* starting_from, bool is_visible) override; 236 void VisibilityChanged(View* starting_from, bool is_visible) override;
237 void OnPaint(gfx::Canvas* canvas) override; 237 void OnPaint(gfx::Canvas* canvas) override;
238 void OnDeviceScaleFactorChanged(float device_scale_factor) override; 238 void OnDeviceScaleFactorChanged(float device_scale_factor) override;
239 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; 239 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
240 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; 240 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override;
241 void OnFocus() override; 241 void OnFocus() override;
242 void OnBlur() override; 242 void OnBlur() override;
243 bool OnMousePressed(const ui::MouseEvent& event) override; 243 bool OnMousePressed(const ui::MouseEvent& event) override;
244 bool OnMouseDragged(const ui::MouseEvent& event) override; 244 bool OnMouseDragged(const ui::MouseEvent& event) override;
245 void OnMouseReleased(const ui::MouseEvent& event) override; 245 void OnMouseReleased(const ui::MouseEvent& event) override;
246 void OnMouseCaptureLost() override; 246 void OnMouseCaptureLost() override;
247 bool OnKeyPressed(const ui::KeyEvent& event) override; 247 bool OnKeyPressed(const ui::KeyEvent& event) override;
248 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; 248 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
249 bool CanHandleAccelerators() const override; 249 bool CanHandleAccelerators() const override;
250 250
251 private: 251 private:
252 FRIEND_TEST_ALL_PREFIXES(LabelTest, ResetRenderTextData); 252 FRIEND_TEST_ALL_PREFIXES(LabelTest, ResetRenderTextData);
253 FRIEND_TEST_ALL_PREFIXES(LabelTest, MultilineSupportedRenderText); 253 FRIEND_TEST_ALL_PREFIXES(LabelTest, MultilineSupportedRenderText);
254 FRIEND_TEST_ALL_PREFIXES(LabelTest, TextChangeWithoutLayout); 254 FRIEND_TEST_ALL_PREFIXES(LabelTest, TextChangeWithoutLayout);
255 FRIEND_TEST_ALL_PREFIXES(LabelTest, EmptyLabel); 255 FRIEND_TEST_ALL_PREFIXES(LabelTest, EmptyLabel);
256 FRIEND_TEST_ALL_PREFIXES(LabelTest, FocusBounds); 256 FRIEND_TEST_ALL_PREFIXES(MDLabelTest, FocusBounds);
257 FRIEND_TEST_ALL_PREFIXES(LabelTest, MultiLineSizingWithElide); 257 FRIEND_TEST_ALL_PREFIXES(LabelTest, MultiLineSizingWithElide);
258 friend class LabelSelectionTest; 258 friend class LabelSelectionTest;
259 259
260 // ContextMenuController overrides: 260 // ContextMenuController overrides:
261 void ShowContextMenuForView(View* source, 261 void ShowContextMenuForView(View* source,
262 const gfx::Point& point, 262 const gfx::Point& point,
263 ui::MenuSourceType source_type) override; 263 ui::MenuSourceType source_type) override;
264 264
265 // WordLookupClient overrides: 265 // WordLookupClient overrides:
266 bool GetDecoratedWordAtPoint(const gfx::Point& point, 266 bool GetDecoratedWordAtPoint(const gfx::Point& point,
(...skipping 23 matching lines...) Expand all
290 290
291 const gfx::RenderText* GetRenderTextForSelectionController() const; 291 const gfx::RenderText* GetRenderTextForSelectionController() const;
292 292
293 void Init(const base::string16& text, const gfx::FontList& font_list); 293 void Init(const base::string16& text, const gfx::FontList& font_list);
294 294
295 void ResetLayout(); 295 void ResetLayout();
296 296
297 // Set up |lines_| to actually be painted. 297 // Set up |lines_| to actually be painted.
298 void MaybeBuildRenderTextLines() const; 298 void MaybeBuildRenderTextLines() const;
299 299
300 gfx::Rect GetFocusBounds() const;
301
302 // Get the text broken into lines as needed to fit the given |width|. 300 // Get the text broken into lines as needed to fit the given |width|.
303 std::vector<base::string16> GetLinesForWidth(int width) const; 301 std::vector<base::string16> GetLinesForWidth(int width) const;
304 302
305 // Get the text size for the current layout. 303 // Get the text size for the current layout.
306 gfx::Size GetTextSize() const; 304 gfx::Size GetTextSize() const;
307 305
308 // Updates |actual_{enabled,disabled}_color_| from requested colors. 306 // Updates |actual_{enabled,disabled}_color_| from requested colors.
309 void RecalculateColors(); 307 void RecalculateColors();
310 308
311 // Applies |actual_{enabled,disabled}_color_| to |lines_|. 309 // Applies |actual_{enabled,disabled}_color_| to |lines_|.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 // Context menu related members. 375 // Context menu related members.
378 ui::SimpleMenuModel context_menu_contents_; 376 ui::SimpleMenuModel context_menu_contents_;
379 std::unique_ptr<views::MenuRunner> context_menu_runner_; 377 std::unique_ptr<views::MenuRunner> context_menu_runner_;
380 378
381 DISALLOW_COPY_AND_ASSIGN(Label); 379 DISALLOW_COPY_AND_ASSIGN(Label);
382 }; 380 };
383 381
384 } // namespace views 382 } // namespace views
385 383
386 #endif // UI_VIEWS_CONTROLS_LABEL_H_ 384 #endif // UI_VIEWS_CONTROLS_LABEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/harmony/layout_provider_unittest.cc ('k') | ui/views/controls/label.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698