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

Side by Side Diff: chrome/browser/ui/views/infobars/infobar_view.cc

Issue 6452011: Rework tree APIs to reflect Google style and more const-correctness.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 10 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/views/infobars/infobar_view.h" 5 #include "chrome/browser/ui/views/infobars/infobar_view.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/ui/views/infobars/infobar_background.h" 9 #include "chrome/browser/ui/views/infobars/infobar_background.h"
10 #include "chrome/browser/ui/views/infobars/infobar_container.h" 10 #include "chrome/browser/ui/views/infobars/infobar_container.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 if (GetWidget() && 87 if (GetWidget() &&
88 !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) { 88 !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) {
89 restore_focus = false; 89 restore_focus = false;
90 } 90 }
91 #endif // defined(OS_WIN) 91 #endif // defined(OS_WIN)
92 DestroyFocusTracker(restore_focus); 92 DestroyFocusTracker(restore_focus);
93 animation_->Hide(); 93 animation_->Hide();
94 } 94 }
95 95
96 void InfoBarView::Close() { 96 void InfoBarView::Close() {
97 GetParent()->RemoveChildView(this); 97 parent()->RemoveChildView(this);
98 // Note that we only tell the delegate we're closed here, and not when we're 98 // Note that we only tell the delegate we're closed here, and not when we're
99 // simply destroyed (by virtue of a tab switch or being moved from window to 99 // simply destroyed (by virtue of a tab switch or being moved from window to
100 // window), since this action can cause the delegate to destroy itself. 100 // window), since this action can cause the delegate to destroy itself.
101 if (delegate_) { 101 if (delegate_) {
102 delegate_->InfoBarClosed(); 102 delegate_->InfoBarClosed();
103 delegate_ = NULL; 103 delegate_ = NULL;
104 } 104 }
105 } 105 }
106 106
107 void InfoBarView::PaintArrow(gfx::Canvas* canvas, 107 void InfoBarView::PaintArrow(gfx::Canvas* canvas,
108 views::View* outer_view, 108 views::View* outer_view,
109 int arrow_center_x) { 109 int arrow_center_x) {
110 gfx::Point infobar_top(0, y()); 110 gfx::Point infobar_top(0, y());
111 ConvertPointToView(GetParent(), outer_view, &infobar_top); 111 ConvertPointToView(parent(), outer_view, &infobar_top);
112 int infobar_top_y = infobar_top.y(); 112 int infobar_top_y = infobar_top.y();
113 113
114 // The size of the arrow (its height; also half its width). The 114 // The size of the arrow (its height; also half its width). The
115 // arrow area is |arrow_size| ^ 2. By taking the square root of the 115 // arrow area is |arrow_size| ^ 2. By taking the square root of the
116 // animation value, we cause a linear animation of the area, which 116 // animation value, we cause a linear animation of the area, which
117 // matches the perception of the animation of the InfoBar. 117 // matches the perception of the animation of the InfoBar.
118 const int kArrowSize = 10; 118 const int kArrowSize = 10;
119 int arrow_size = static_cast<int>(kArrowSize * 119 int arrow_size = static_cast<int>(kArrowSize *
120 sqrt(animation_->GetCurrentValue())); 120 sqrt(animation_->GetCurrentValue()));
121 121
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // since no-one refers to us now. 196 // since no-one refers to us now.
197 MessageLoop::current()->PostTask(FROM_HERE, 197 MessageLoop::current()->PostTask(FROM_HERE,
198 delete_factory_.NewRunnableMethod(&InfoBarView::DeleteSelf)); 198 delete_factory_.NewRunnableMethod(&InfoBarView::DeleteSelf));
199 if (GetFocusManager()) 199 if (GetFocusManager())
200 GetFocusManager()->RemoveFocusChangeListener(this); 200 GetFocusManager()->RemoveFocusChangeListener(this);
201 } 201 }
202 } 202 }
203 203
204 // For accessibility, ensure the close button is the last child view. 204 // For accessibility, ensure the close button is the last child view.
205 if ((parent == this) && (child != close_button_) && 205 if ((parent == this) && (child != close_button_) &&
206 HasChildView(close_button_) && 206 (close_button_->parent() == this) &&
207 (GetChildViewAt(GetChildViewCount() - 1) != close_button_)) { 207 (GetChildViewAt(child_count() - 1) != close_button_)) {
208 RemoveChildView(close_button_); 208 RemoveChildView(close_button_);
209 AddChildView(close_button_); 209 AddChildView(close_button_);
210 } 210 }
211 } 211 }
212 212
213 void InfoBarView::ButtonPressed(views::Button* sender, 213 void InfoBarView::ButtonPressed(views::Button* sender,
214 const views::Event& event) { 214 const views::Event& event) {
215 if (sender == close_button_) { 215 if (sender == close_button_) {
216 if (delegate_) 216 if (delegate_)
217 delegate_->InfoBarDismissed(); 217 delegate_->InfoBarDismissed();
(...skipping 28 matching lines...) Expand all
246 } 246 }
247 247
248 gfx::Size InfoBarView::GetPreferredSize() { 248 gfx::Size InfoBarView::GetPreferredSize() {
249 int height = static_cast<int>(target_height_ * animation_->GetCurrentValue()); 249 int height = static_cast<int>(target_height_ * animation_->GetCurrentValue());
250 return gfx::Size(0, height); 250 return gfx::Size(0, height);
251 } 251 }
252 252
253 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { 253 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) {
254 // This will trigger some screen readers to read the entire contents of this 254 // This will trigger some screen readers to read the entire contents of this
255 // infobar. 255 // infobar.
256 if (focused_before && focused_now && !this->IsParentOf(focused_before) && 256 if (focused_before && focused_now && !this->Contains(focused_before) &&
257 this->IsParentOf(focused_now)) 257 this->Contains(focused_now))
258 NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT); 258 NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT);
259 } 259 }
260 260
261 void InfoBarView::AnimationEnded(const ui::Animation* animation) { 261 void InfoBarView::AnimationEnded(const ui::Animation* animation) {
262 if (container_) { 262 if (container_) {
263 container_->InfoBarAnimated(false); 263 container_->InfoBarAnimated(false);
264 264
265 if (!animation_->IsShowing()) 265 if (!animation_->IsShowing())
266 Close(); 266 Close();
267 } 267 }
268 } 268 }
269 269
270 void InfoBarView::DestroyFocusTracker(bool restore_focus) { 270 void InfoBarView::DestroyFocusTracker(bool restore_focus) {
271 if (focus_tracker_ != NULL) { 271 if (focus_tracker_ != NULL) {
272 if (restore_focus) 272 if (restore_focus)
273 focus_tracker_->FocusLastFocusedExternalView(); 273 focus_tracker_->FocusLastFocusedExternalView();
274 focus_tracker_->SetFocusManager(NULL); 274 focus_tracker_->SetFocusManager(NULL);
275 focus_tracker_.reset(); 275 focus_tracker_.reset();
276 } 276 }
277 } 277 }
278 278
279 void InfoBarView::DeleteSelf() { 279 void InfoBarView::DeleteSelf() {
280 delete this; 280 delete this;
281 } 281 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698