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

Side by Side Diff: ui/message_center/views/padded_button.cc

Issue 78803002: Fixing focus highlight on high DPI devices for accessibility (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « ui/message_center/views/padded_button.h ('k') | ui/views/controls/slider.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "ui/message_center/views/padded_button.h" 5 #include "ui/message_center/views/padded_button.h"
6 6
7 #include "grit/ui_resources.h" 7 #include "grit/ui_resources.h"
8 #include "ui/base/resource/resource_bundle.h" 8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/message_center/message_center_style.h" 10 #include "ui/message_center/message_center_style.h"
11 #include "ui/views/controls/button/image_button.h" 11 #include "ui/views/controls/button/image_button.h"
12 12
13 namespace message_center { 13 namespace message_center {
14 14
15 PaddedButton::PaddedButton(views::ButtonListener* listener) 15 PaddedButton::PaddedButton(views::ButtonListener* listener)
16 : views::ImageButton(listener) { 16 : views::ImageButton(listener) {
17 set_focusable(true); 17 set_focusable(true);
18 set_request_focus_on_press(false); 18 set_request_focus_on_press(false);
19 set_focus_border(views::FocusBorder::CreateSolidFocusBorder(
20 kFocusBorderColor,
21 gfx::Insets(1, 2, 2, 2)));
19 } 22 }
20 23
21 PaddedButton::~PaddedButton() { 24 PaddedButton::~PaddedButton() {
22 } 25 }
23 26
24 void PaddedButton::SetPadding(int horizontal_padding, int vertical_padding) { 27 void PaddedButton::SetPadding(int horizontal_padding, int vertical_padding) {
25 padding_.Set(std::max(vertical_padding, 0), 28 padding_.Set(std::max(vertical_padding, 0),
26 std::max(horizontal_padding, 0), 29 std::max(horizontal_padding, 0),
27 std::max(-vertical_padding, 0), 30 std::max(-vertical_padding, 0),
28 std::max(-horizontal_padding, 0)); 31 std::max(-horizontal_padding, 0));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 canvas->DrawImageInt(overlay_image_, position.x(), position.y()); 69 canvas->DrawImageInt(overlay_image_, position.x(), position.y());
67 } 70 }
68 OnPaintFocusBorder(canvas); 71 OnPaintFocusBorder(canvas);
69 } 72 }
70 73
71 void PaddedButton::OnFocus() { 74 void PaddedButton::OnFocus() {
72 views::ImageButton::OnFocus(); 75 views::ImageButton::OnFocus();
73 ScrollRectToVisible(GetLocalBounds()); 76 ScrollRectToVisible(GetLocalBounds());
74 } 77 }
75 78
76 void PaddedButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
77 if (HasFocus()) {
78 canvas->DrawRect(gfx::Rect(2, 1, width() - 4, height() - 3),
79 message_center::kFocusBorderColor);
80 }
81 }
82
83 gfx::Point PaddedButton::ComputePaddedImagePaintPosition( 79 gfx::Point PaddedButton::ComputePaddedImagePaintPosition(
84 const gfx::ImageSkia& image) { 80 const gfx::ImageSkia& image) {
85 gfx::Vector2d offset; 81 gfx::Vector2d offset;
86 gfx::Rect bounds = GetContentsBounds(); 82 gfx::Rect bounds = GetContentsBounds();
87 bounds.Inset(padding_); 83 bounds.Inset(padding_);
88 84
89 if (padding_.left() == 0 && padding_.right() == 0) 85 if (padding_.left() == 0 && padding_.right() == 0)
90 offset.set_x((bounds.width() - image.width()) / 2); // Center align. 86 offset.set_x((bounds.width() - image.width()) / 2); // Center align.
91 else if (padding_.right() > 0) 87 else if (padding_.right() > 0)
92 offset.set_x(bounds.width() - image.width()); // Right align. 88 offset.set_x(bounds.width() - image.width()); // Right align.
93 89
94 if (padding_.top() == 0 && padding_.bottom() == 0) 90 if (padding_.top() == 0 && padding_.bottom() == 0)
95 offset.set_y((bounds.height() - image.height()) / 2); // Middle align. 91 offset.set_y((bounds.height() - image.height()) / 2); // Middle align.
96 else if (padding_.bottom() > 0) 92 else if (padding_.bottom() > 0)
97 offset.set_y(bounds.height() - image.height()); // Bottom align. 93 offset.set_y(bounds.height() - image.height()); // Bottom align.
98 94
99 return bounds.origin() + offset; 95 return bounds.origin() + offset;
100 } 96 }
101 97
102 } // namespace message_center 98 } // namespace message_center
103 99
OLDNEW
« no previous file with comments | « ui/message_center/views/padded_button.h ('k') | ui/views/controls/slider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698