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

Side by Side Diff: chrome/views/controls/button/checkbox.cc

Issue 92004: Fix focus rects for checkboxes and radio buttons:... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/views/controls/button/checkbox.h ('k') | chrome/views/controls/button/radio_button.h » ('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) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "chrome/views/controls/button/checkbox.h" 5 #include "chrome/views/controls/button/checkbox.h"
6 6
7 #include "chrome/common/gfx/chrome_canvas.h" 7 #include "chrome/common/gfx/chrome_canvas.h"
8 #include "chrome/views/controls/label.h" 8 #include "chrome/views/controls/label.h"
9 9
10 namespace views { 10 namespace views {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 label_->SetBounds( 75 label_->SetBounds(
76 label_x, 0, std::max(0, width() - label_x - kLabelFocusPaddingHorizontal), 76 label_x, 0, std::max(0, width() - label_x - kLabelFocusPaddingHorizontal),
77 height()); 77 height());
78 int first_line_height = label_->GetFont().height(); 78 int first_line_height = label_->GetFont().height();
79 native_wrapper_->GetView()->SetBounds( 79 native_wrapper_->GetView()->SetBounds(
80 0, ((first_line_height - checkmark_prefsize.height()) / 2), 80 0, ((first_line_height - checkmark_prefsize.height()) / 2),
81 checkmark_prefsize.width(), checkmark_prefsize.height()); 81 checkmark_prefsize.width(), checkmark_prefsize.height());
82 native_wrapper_->GetView()->Layout(); 82 native_wrapper_->GetView()->Layout();
83 } 83 }
84 84
85 void Checkbox::Paint(ChromeCanvas* canvas) { 85 void Checkbox::PaintFocusBorder(ChromeCanvas* canvas) {
86 // Paint the focus border manually since we don't want to send actual focus 86 // Our focus border is rendered by the label, so we don't do anything here.
87 // in to the inner view.
88 if (HasFocus()) {
89 gfx::Rect label_bounds = label_->bounds();
90 canvas->DrawFocusRect(
91 MirroredLeftPointForRect(label_bounds) - kLabelFocusPaddingHorizontal,
92 0,
93 label_bounds.width() + kLabelFocusPaddingHorizontal * 2,
94 label_bounds.height() - kLabelFocusPaddingVertical * 2);
95 }
96 } 87 }
97 88
98 View* Checkbox::GetViewForPoint(const gfx::Point& point) { 89 View* Checkbox::GetViewForPoint(const gfx::Point& point) {
99 return GetViewForPoint(point, false); 90 return GetViewForPoint(point, false);
100 } 91 }
101 92
102 View* Checkbox::GetViewForPoint(const gfx::Point& point, 93 View* Checkbox::GetViewForPoint(const gfx::Point& point,
103 bool can_create_floating) { 94 bool can_create_floating) {
104 return GetLocalBounds(true).Contains(point) ? this : NULL; 95 return GetLocalBounds(true).Contains(point) ? this : NULL;
105 } 96 }
(...skipping 16 matching lines...) Expand all
122 } 113 }
123 114
124 void Checkbox::OnMouseReleased(const MouseEvent& e, bool canceled) { 115 void Checkbox::OnMouseReleased(const MouseEvent& e, bool canceled) {
125 native_wrapper_->SetPushed(false); 116 native_wrapper_->SetPushed(false);
126 if (!canceled && HitTestLabel(e)) { 117 if (!canceled && HitTestLabel(e)) {
127 SetChecked(!checked()); 118 SetChecked(!checked());
128 ButtonPressed(); 119 ButtonPressed();
129 } 120 }
130 } 121 }
131 122
123 bool Checkbox::OnMouseDragged(const MouseEvent& e) {
124 return false;
125 }
126
127 void Checkbox::WillGainFocus() {
128 label_->set_paint_as_focused(true);
129 }
130
131 void Checkbox::WillLoseFocus() {
132 label_->set_paint_as_focused(false);
133 }
134
132 std::string Checkbox::GetClassName() const { 135 std::string Checkbox::GetClassName() const {
133 return kViewClassName; 136 return kViewClassName;
134 } 137 }
135 138
136 //////////////////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////////////////
137 // Checkbox, NativeButton overrides: 140 // Checkbox, NativeButton overrides:
138 141
139 void Checkbox::CreateWrapper() { 142 void Checkbox::CreateWrapper() {
140 native_wrapper_ = NativeButtonWrapper::CreateCheckboxWrapper(this); 143 native_wrapper_ = NativeButtonWrapper::CreateCheckboxWrapper(this);
141 native_wrapper_->UpdateLabel(); 144 native_wrapper_->UpdateLabel();
142 native_wrapper_->UpdateChecked(); 145 native_wrapper_->UpdateChecked();
143 } 146 }
144 147
145 void Checkbox::InitBorder() { 148 void Checkbox::InitBorder() {
146 // No border, so we do nothing. 149 // No border, so we do nothing.
147 } 150 }
148 151
149 //////////////////////////////////////////////////////////////////////////////// 152 ////////////////////////////////////////////////////////////////////////////////
153 // Checkbox, protected:
154
155 bool Checkbox::HitTestLabel(const MouseEvent& e) {
156 gfx::Point tmp(e.location());
157 ConvertPointToView(this, label_, &tmp);
158 return label_->HitTest(tmp);
159 }
160
161 ////////////////////////////////////////////////////////////////////////////////
150 // Checkbox, private: 162 // Checkbox, private:
151 163
152 void Checkbox::Init(const std::wstring& label_text) { 164 void Checkbox::Init(const std::wstring& label_text) {
153 set_minimum_size(gfx::Size(0, 0)); 165 set_minimum_size(gfx::Size(0, 0));
154 label_ = new Label(label_text); 166 label_ = new Label(label_text);
155 label_->SetHorizontalAlignment(Label::ALIGN_LEFT); 167 label_->SetHorizontalAlignment(Label::ALIGN_LEFT);
156 AddChildView(label_); 168 AddChildView(label_);
157 } 169 }
158 170
159 bool Checkbox::HitTestLabel(const MouseEvent& e) {
160 gfx::Point tmp(e.location());
161 ConvertPointToView(this, label_, &tmp);
162 return label_->HitTest(tmp);
163 }
164
165 } // namespace views 171 } // namespace views
OLDNEW
« no previous file with comments | « chrome/views/controls/button/checkbox.h ('k') | chrome/views/controls/button/radio_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698