| OLD | NEW |
| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // top-level window became active. | 83 // top-level window became active. |
| 84 if (GetWidget() && | 84 if (GetWidget() && |
| 85 !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) | 85 !ui::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) |
| 86 restore_focus = false; | 86 restore_focus = false; |
| 87 #endif // defined(OS_WIN) | 87 #endif // defined(OS_WIN) |
| 88 DestroyFocusTracker(restore_focus); | 88 DestroyFocusTracker(restore_focus); |
| 89 animation_->Hide(); | 89 animation_->Hide(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void InfoBarView::Close() { | 92 void InfoBarView::Close() { |
| 93 GetParent()->RemoveChildView(this); | 93 parent()->RemoveChildView(this); |
| 94 // Note that we only tell the delegate we're closed here, and not when we're | 94 // Note that we only tell the delegate we're closed here, and not when we're |
| 95 // simply destroyed (by virtue of a tab switch or being moved from window to | 95 // simply destroyed (by virtue of a tab switch or being moved from window to |
| 96 // window), since this action can cause the delegate to destroy itself. | 96 // window), since this action can cause the delegate to destroy itself. |
| 97 if (delegate_) { | 97 if (delegate_) { |
| 98 delegate_->InfoBarClosed(); | 98 delegate_->InfoBarClosed(); |
| 99 delegate_ = NULL; | 99 delegate_ = NULL; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 void InfoBarView::PaintArrow(gfx::Canvas* canvas, | 103 void InfoBarView::PaintArrow(gfx::Canvas* canvas, |
| 104 View* outer_view, | 104 View* outer_view, |
| 105 int arrow_center_x) { | 105 int arrow_center_x) { |
| 106 gfx::Point infobar_top(0, y()); | 106 gfx::Point infobar_top(0, y()); |
| 107 ConvertPointToView(GetParent(), outer_view, &infobar_top); | 107 ConvertPointToView(parent(), outer_view, &infobar_top); |
| 108 int infobar_top_y = infobar_top.y(); | 108 int infobar_top_y = infobar_top.y(); |
| 109 SkPoint gradient_points[2] = { | 109 SkPoint gradient_points[2] = { |
| 110 {SkIntToScalar(0), SkIntToScalar(infobar_top_y)}, | 110 {SkIntToScalar(0), SkIntToScalar(infobar_top_y)}, |
| 111 {SkIntToScalar(0), SkIntToScalar(infobar_top_y + target_height_)} | 111 {SkIntToScalar(0), SkIntToScalar(infobar_top_y + target_height_)} |
| 112 }; | 112 }; |
| 113 InfoBarDelegate::Type infobar_type = delegate_->GetInfoBarType(); | 113 InfoBarDelegate::Type infobar_type = delegate_->GetInfoBarType(); |
| 114 SkColor gradient_colors[2] = { | 114 SkColor gradient_colors[2] = { |
| 115 InfoBarBackground::GetTopColor(infobar_type), | 115 InfoBarBackground::GetTopColor(infobar_type), |
| 116 InfoBarBackground::GetBottomColor(infobar_type), | 116 InfoBarBackground::GetBottomColor(infobar_type), |
| 117 }; | 117 }; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // since no-one refers to us now. | 187 // since no-one refers to us now. |
| 188 MessageLoop::current()->PostTask(FROM_HERE, | 188 MessageLoop::current()->PostTask(FROM_HERE, |
| 189 delete_factory_.NewRunnableMethod(&InfoBarView::DeleteSelf)); | 189 delete_factory_.NewRunnableMethod(&InfoBarView::DeleteSelf)); |
| 190 if (GetFocusManager()) | 190 if (GetFocusManager()) |
| 191 GetFocusManager()->RemoveFocusChangeListener(this); | 191 GetFocusManager()->RemoveFocusChangeListener(this); |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 // For accessibility, ensure the close button is the last child view. | 195 // For accessibility, ensure the close button is the last child view. |
| 196 if ((parent == this) && (child != close_button_) && | 196 if ((parent == this) && (child != close_button_) && |
| 197 HasChildView(close_button_) && | 197 (close_button_->parent() == this) && |
| 198 (GetChildViewAt(GetChildViewCount() - 1) != close_button_)) { | 198 (GetChildViewAt(child_count() - 1) != close_button_)) { |
| 199 RemoveChildView(close_button_); | 199 RemoveChildView(close_button_); |
| 200 AddChildView(close_button_); | 200 AddChildView(close_button_); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 void InfoBarView::ButtonPressed(views::Button* sender, | 204 void InfoBarView::ButtonPressed(views::Button* sender, |
| 205 const views::Event& event) { | 205 const views::Event& event) { |
| 206 if (sender == close_button_) { | 206 if (sender == close_button_) { |
| 207 if (delegate_) | 207 if (delegate_) |
| 208 delegate_->InfoBarDismissed(); | 208 delegate_->InfoBarDismissed(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 238 } | 238 } |
| 239 | 239 |
| 240 gfx::Size InfoBarView::GetPreferredSize() { | 240 gfx::Size InfoBarView::GetPreferredSize() { |
| 241 return gfx::Size(0, | 241 return gfx::Size(0, |
| 242 static_cast<int>(target_height_ * animation_->GetCurrentValue())); | 242 static_cast<int>(target_height_ * animation_->GetCurrentValue())); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { | 245 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { |
| 246 // This will trigger some screen readers to read the entire contents of this | 246 // This will trigger some screen readers to read the entire contents of this |
| 247 // infobar. | 247 // infobar. |
| 248 if (focused_before && focused_now && !this->IsParentOf(focused_before) && | 248 if (focused_before && focused_now && !this->Contains(focused_before) && |
| 249 this->IsParentOf(focused_now)) | 249 this->Contains(focused_now)) |
| 250 NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT); | 250 NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void InfoBarView::AnimationEnded(const ui::Animation* animation) { | 253 void InfoBarView::AnimationEnded(const ui::Animation* animation) { |
| 254 if (container_) { | 254 if (container_) { |
| 255 container_->InfoBarAnimated(false); | 255 container_->InfoBarAnimated(false); |
| 256 | 256 |
| 257 if (!animation_->IsShowing()) | 257 if (!animation_->IsShowing()) |
| 258 Close(); | 258 Close(); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 void InfoBarView::DestroyFocusTracker(bool restore_focus) { | 262 void InfoBarView::DestroyFocusTracker(bool restore_focus) { |
| 263 if (focus_tracker_ != NULL) { | 263 if (focus_tracker_ != NULL) { |
| 264 if (restore_focus) | 264 if (restore_focus) |
| 265 focus_tracker_->FocusLastFocusedExternalView(); | 265 focus_tracker_->FocusLastFocusedExternalView(); |
| 266 focus_tracker_->SetFocusManager(NULL); | 266 focus_tracker_->SetFocusManager(NULL); |
| 267 focus_tracker_.reset(); | 267 focus_tracker_.reset(); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 void InfoBarView::DeleteSelf() { | 271 void InfoBarView::DeleteSelf() { |
| 272 delete this; | 272 delete this; |
| 273 } | 273 } |
| OLD | NEW |