| OLD | NEW |
| 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 #include "chrome/browser/ui/views/infobars/infobar_view.h" | 5 #include "chrome/browser/ui/views/infobars/infobar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 const int kBeforeCloseButtonSpacing = views::kUnrelatedControlHorizontalSpacing; | 41 const int kBeforeCloseButtonSpacing = views::kUnrelatedControlHorizontalSpacing; |
| 42 | 42 |
| 43 bool SortLabelsByDecreasingWidth(views::Label* label_1, views::Label* label_2) { | 43 bool SortLabelsByDecreasingWidth(views::Label* label_1, views::Label* label_2) { |
| 44 return label_1->GetPreferredSize().width() > | 44 return label_1->GetPreferredSize().width() > |
| 45 label_2->GetPreferredSize().width(); | 45 label_2->GetPreferredSize().width(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 | 50 |
| 51 // InfoBar -------------------------------------------------------------------- | |
| 52 | |
| 53 // static | |
| 54 const int infobars::InfoBar::kSeparatorLineHeight = | |
| 55 views::NonClientFrameView::kClientEdgeThickness; | |
| 56 const int infobars::InfoBar::kDefaultArrowTargetHeight = 9; | |
| 57 const int infobars::InfoBar::kMaximumArrowTargetHeight = 24; | |
| 58 const int infobars::InfoBar::kDefaultArrowTargetHalfWidth = | |
| 59 kDefaultArrowTargetHeight; | |
| 60 const int infobars::InfoBar::kMaximumArrowTargetHalfWidth = 14; | |
| 61 const int infobars::InfoBar::kDefaultBarTargetHeight = 36; | |
| 62 | |
| 63 // InfoBarView ---------------------------------------------------------------- | 51 // InfoBarView ---------------------------------------------------------------- |
| 64 | 52 |
| 65 // static | 53 // static |
| 66 const int InfoBarView::kButtonButtonSpacing = views::kRelatedButtonHSpacing; | 54 const int InfoBarView::kButtonButtonSpacing = views::kRelatedButtonHSpacing; |
| 67 const int InfoBarView::kEndOfLabelSpacing = views::kItemLabelSpacing; | 55 const int InfoBarView::kEndOfLabelSpacing = views::kItemLabelSpacing; |
| 68 | 56 |
| 69 InfoBarView::InfoBarView(scoped_ptr<infobars::InfoBarDelegate> delegate) | 57 InfoBarView::InfoBarView(scoped_ptr<infobars::InfoBarDelegate> delegate) |
| 70 : infobars::InfoBar(delegate.Pass()), | 58 : infobars::InfoBar(delegate.Pass()), |
| 71 views::ExternalFocusTracker(this, NULL), | 59 views::ExternalFocusTracker(this, NULL), |
| 72 icon_(NULL), | 60 icon_(NULL), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // PlatformSpecificRecalculateHeight(), because this is also reached when our | 136 // PlatformSpecificRecalculateHeight(), because this is also reached when our |
| 149 // width is changed, which affects both paths. | 137 // width is changed, which affects both paths. |
| 150 stroke_path_.rewind(); | 138 stroke_path_.rewind(); |
| 151 fill_path_.rewind(); | 139 fill_path_.rewind(); |
| 152 const infobars::InfoBarContainer::Delegate* delegate = container_delegate(); | 140 const infobars::InfoBarContainer::Delegate* delegate = container_delegate(); |
| 153 if (delegate) { | 141 if (delegate) { |
| 154 static_cast<InfoBarBackground*>(background())->set_separator_color( | 142 static_cast<InfoBarBackground*>(background())->set_separator_color( |
| 155 delegate->GetInfoBarSeparatorColor()); | 143 delegate->GetInfoBarSeparatorColor()); |
| 156 int arrow_x; | 144 int arrow_x; |
| 157 SkScalar arrow_fill_height = | 145 SkScalar arrow_fill_height = |
| 158 SkIntToScalar(std::max(arrow_height() - kSeparatorLineHeight, 0)); | 146 SkIntToScalar(std::max(arrow_height() - gSeparatorLineHeight, 0)); |
| 159 SkScalar arrow_fill_half_width = SkIntToScalar(arrow_half_width()); | 147 SkScalar arrow_fill_half_width = SkIntToScalar(arrow_half_width()); |
| 160 SkScalar separator_height = SkIntToScalar(kSeparatorLineHeight); | 148 SkScalar separator_height = SkIntToScalar(gSeparatorLineHeight); |
| 161 if (delegate->DrawInfoBarArrows(&arrow_x) && arrow_fill_height) { | 149 if (delegate->DrawInfoBarArrows(&arrow_x) && arrow_fill_height) { |
| 162 // Skia pixel centers are at the half-values, so the arrow is horizontally | 150 // Skia pixel centers are at the half-values, so the arrow is horizontally |
| 163 // centered at |arrow_x| + 0.5. Vertically, the stroke path is the center | 151 // centered at |arrow_x| + 0.5. Vertically, the stroke path is the center |
| 164 // of the separator, while the fill path is a closed path that extends up | 152 // of the separator, while the fill path is a closed path that extends up |
| 165 // through the entire height of the separator and down to the bottom of | 153 // through the entire height of the separator and down to the bottom of |
| 166 // the arrow where it joins the bar. | 154 // the arrow where it joins the bar. |
| 167 stroke_path_.moveTo( | 155 stroke_path_.moveTo( |
| 168 SkIntToScalar(arrow_x) + SK_ScalarHalf - arrow_fill_half_width, | 156 SkIntToScalar(arrow_x) + SK_ScalarHalf - arrow_fill_half_width, |
| 169 SkIntToScalar(arrow_height()) - (separator_height * SK_ScalarHalf)); | 157 SkIntToScalar(arrow_height()) - (separator_height * SK_ScalarHalf)); |
| 170 stroke_path_.rLineTo(arrow_fill_half_width, -arrow_fill_height); | 158 stroke_path_.rLineTo(arrow_fill_half_width, -arrow_fill_height); |
| 171 stroke_path_.rLineTo(arrow_fill_half_width, arrow_fill_height); | 159 stroke_path_.rLineTo(arrow_fill_half_width, arrow_fill_height); |
| 172 | 160 |
| 173 fill_path_ = stroke_path_; | 161 fill_path_ = stroke_path_; |
| 174 // Move the top of the fill path up to the top of the separator and then | 162 // Move the top of the fill path up to the top of the separator and then |
| 175 // extend it down all the way through. | 163 // extend it down all the way through. |
| 176 fill_path_.offset(0, -separator_height * SK_ScalarHalf); | 164 fill_path_.offset(0, -separator_height * SK_ScalarHalf); |
| 177 // This 0.01 hack prevents the fill from filling more pixels on the right | 165 // This 0.01 hack prevents the fill from filling more pixels on the right |
| 178 // edge of the arrow than on the left. | 166 // edge of the arrow than on the left. |
| 179 const SkScalar epsilon = 0.01f; | 167 const SkScalar epsilon = 0.01f; |
| 180 fill_path_.rLineTo(-epsilon, 0); | 168 fill_path_.rLineTo(-epsilon, 0); |
| 181 fill_path_.rLineTo(0, separator_height); | 169 fill_path_.rLineTo(0, separator_height); |
| 182 fill_path_.rLineTo(epsilon - (arrow_fill_half_width * 2), 0); | 170 fill_path_.rLineTo(epsilon - (arrow_fill_half_width * 2), 0); |
| 183 fill_path_.close(); | 171 fill_path_.close(); |
| 184 } | 172 } |
| 185 } | 173 } |
| 186 if (bar_height()) { | 174 if (bar_height()) { |
| 187 fill_path_.addRect(0.0, SkIntToScalar(arrow_height()), | 175 fill_path_.addRect(0.0, SkIntToScalar(arrow_height()), |
| 188 SkIntToScalar(width()), SkIntToScalar(height() - kSeparatorLineHeight)); | 176 SkIntToScalar(width()), SkIntToScalar(height() - gSeparatorLineHeight)); |
| 189 } | 177 } |
| 190 | 178 |
| 191 int start_x = kEdgeItemPadding; | 179 int start_x = kEdgeItemPadding; |
| 192 if (icon_ != NULL) { | 180 if (icon_ != NULL) { |
| 193 icon_->SetPosition(gfx::Point(start_x, OffsetY(icon_))); | 181 icon_->SetPosition(gfx::Point(start_x, OffsetY(icon_))); |
| 194 start_x = icon_->bounds().right() + kIconToLabelSpacing; | 182 start_x = icon_->bounds().right() + kIconToLabelSpacing; |
| 195 } | 183 } |
| 196 | 184 |
| 197 int content_minimum_width = ContentMinimumWidth(); | 185 int content_minimum_width = ContentMinimumWidth(); |
| 198 close_button_->SetPosition(gfx::Point( | 186 close_button_->SetPosition(gfx::Point( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } else if ((close_button_ != NULL) && (details.parent == this) && | 220 } else if ((close_button_ != NULL) && (details.parent == this) && |
| 233 (details.child != close_button_) && (close_button_->parent() == this) && | 221 (details.child != close_button_) && (close_button_->parent() == this) && |
| 234 (child_at(child_count() - 1) != close_button_)) { | 222 (child_at(child_count() - 1) != close_button_)) { |
| 235 // For accessibility, ensure the close button is the last child view. | 223 // For accessibility, ensure the close button is the last child view. |
| 236 RemoveChildView(close_button_); | 224 RemoveChildView(close_button_); |
| 237 AddChildView(close_button_); | 225 AddChildView(close_button_); |
| 238 } | 226 } |
| 239 | 227 |
| 240 // Ensure the infobar is tall enough to display its contents. | 228 // Ensure the infobar is tall enough to display its contents. |
| 241 const int kMinimumVerticalPadding = 6; | 229 const int kMinimumVerticalPadding = 6; |
| 242 int height = kDefaultBarTargetHeight; | 230 int height = gDefaultBarTargetHeight; |
| 243 for (int i = 0; i < child_count(); ++i) { | 231 for (int i = 0; i < child_count(); ++i) { |
| 244 const int child_height = child_at(i)->height(); | 232 const int child_height = child_at(i)->height(); |
| 245 height = std::max(height, child_height + kMinimumVerticalPadding); | 233 height = std::max(height, child_height + kMinimumVerticalPadding); |
| 246 } | 234 } |
| 247 SetBarTargetHeight(height); | 235 SetBarTargetHeight(height); |
| 248 } | 236 } |
| 249 | 237 |
| 250 void InfoBarView::PaintChildren(gfx::Canvas* canvas, | 238 void InfoBarView::PaintChildren(gfx::Canvas* canvas, |
| 251 const views::CullSet& cull_set) { | 239 const views::CullSet& cull_set) { |
| 252 canvas->Save(); | 240 canvas->Save(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { | 374 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { |
| 387 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); | 375 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); |
| 388 | 376 |
| 389 // This will trigger some screen readers to read the entire contents of this | 377 // This will trigger some screen readers to read the entire contents of this |
| 390 // infobar. | 378 // infobar. |
| 391 if (focused_before && focused_now && !Contains(focused_before) && | 379 if (focused_before && focused_now && !Contains(focused_before) && |
| 392 Contains(focused_now)) { | 380 Contains(focused_now)) { |
| 393 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 381 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| 394 } | 382 } |
| 395 } | 383 } |
| OLD | NEW |