| 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 "ash/common/system/tray/tray_details_view.h" | 5 #include "ash/common/system/tray/tray_details_view.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_view_ids.h" | 7 #include "ash/common/ash_view_ids.h" |
| 8 #include "ash/common/material_design/material_design_controller.h" | |
| 9 #include "ash/common/system/tray/system_menu_button.h" | 8 #include "ash/common/system/tray/system_menu_button.h" |
| 10 #include "ash/common/system/tray/system_tray.h" | 9 #include "ash/common/system/tray/system_tray.h" |
| 11 #include "ash/common/system/tray/system_tray_item.h" | 10 #include "ash/common/system/tray/system_tray_item.h" |
| 12 #include "ash/common/system/tray/tray_constants.h" | 11 #include "ash/common/system/tray/tray_constants.h" |
| 13 #include "ash/common/system/tray/tray_popup_item_style.h" | 12 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 14 #include "ash/common/system/tray/tray_popup_utils.h" | 13 #include "ash/common/system/tray/tray_popup_utils.h" |
| 15 #include "ash/common/system/tray/tri_view.h" | 14 #include "ash/common/system/tray/tri_view.h" |
| 16 #include "ash/strings/grit/ash_strings.h" | 15 #include "ash/strings/grit/ash_strings.h" |
| 17 #include "base/containers/adapters.h" | 16 #include "base/containers/adapters.h" |
| 18 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 19 #include "third_party/skia/include/core/SkDrawLooper.h" | 18 #include "third_party/skia/include/core/SkDrawLooper.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/compositor/paint_context.h" | 20 #include "ui/compositor/paint_context.h" |
| 22 #include "ui/compositor/paint_recorder.h" | 21 #include "ui/compositor/paint_recorder.h" |
| 23 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 24 #include "ui/gfx/skia_paint_util.h" | 23 #include "ui/gfx/skia_paint_util.h" |
| 25 #include "ui/views/background.h" | 24 #include "ui/views/background.h" |
| 26 #include "ui/views/border.h" | 25 #include "ui/views/border.h" |
| 27 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
| 28 #include "ui/views/controls/progress_bar.h" | 27 #include "ui/views/controls/progress_bar.h" |
| 29 #include "ui/views/controls/scroll_view.h" | 28 #include "ui/views/controls/scroll_view.h" |
| 30 #include "ui/views/controls/separator.h" | 29 #include "ui/views/controls/separator.h" |
| 31 #include "ui/views/layout/box_layout.h" | 30 #include "ui/views/layout/box_layout.h" |
| 32 #include "ui/views/view_targeter.h" | 31 #include "ui/views/view_targeter.h" |
| 33 #include "ui/views/view_targeter_delegate.h" | 32 #include "ui/views/view_targeter_delegate.h" |
| 34 | 33 |
| 35 namespace ash { | 34 namespace ash { |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 bool UseMd() { | |
| 39 return MaterialDesignController::IsSystemTrayMenuMaterial(); | |
| 40 } | |
| 41 | |
| 42 // The index of the horizontal rule below the title row. | 37 // The index of the horizontal rule below the title row. |
| 43 const int kTitleRowSeparatorIndex = 1; | 38 const int kTitleRowSeparatorIndex = 1; |
| 44 | 39 |
| 45 // A view that is used as ScrollView contents. It supports designating some of | 40 // A view that is used as ScrollView contents. It supports designating some of |
| 46 // the children as sticky header rows. The sticky header rows are not scrolled | 41 // the children as sticky header rows. The sticky header rows are not scrolled |
| 47 // above the top of the visible viewport until the next one "pushes" it up and | 42 // above the top of the visible viewport until the next one "pushes" it up and |
| 48 // are painted above other children. To indicate that a child is a sticky header | 43 // are painted above other children. To indicate that a child is a sticky header |
| 49 // row use set_id(VIEW_ID_STICKY_HEADER). | 44 // row use set_id(VIEW_ID_STICKY_HEADER). |
| 50 class ScrollContentsView : public views::View { | 45 class ScrollContentsView : public views::View { |
| 51 public: | 46 public: |
| 52 ScrollContentsView() | 47 ScrollContentsView() |
| 53 : box_layout_(new views::BoxLayout( | 48 : box_layout_( |
| 54 views::BoxLayout::kVertical, | 49 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)) { |
| 55 0, | |
| 56 0, | |
| 57 UseMd() ? 0 : kContentsBetweenChildSpacingNonMd)) { | |
| 58 SetLayoutManager(box_layout_); | 50 SetLayoutManager(box_layout_); |
| 59 } | 51 } |
| 60 ~ScrollContentsView() override {} | 52 ~ScrollContentsView() override {} |
| 61 | 53 |
| 62 protected: | 54 protected: |
| 63 // views::View: | 55 // views::View: |
| 64 void OnBoundsChanged(const gfx::Rect& previous_bounds) override { | 56 void OnBoundsChanged(const gfx::Rect& previous_bounds) override { |
| 65 PositionHeaderRows(); | 57 PositionHeaderRows(); |
| 66 } | 58 } |
| 67 | 59 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 gfx::Insets(details.child->id() == VIEW_ID_STICKY_HEADER | 118 gfx::Insets(details.child->id() == VIEW_ID_STICKY_HEADER |
| 127 ? 0 | 119 ? 0 |
| 128 : kMenuSeparatorVerticalPadding, | 120 : kMenuSeparatorVerticalPadding, |
| 129 0, kMenuSeparatorVerticalPadding, 0)); | 121 0, kMenuSeparatorVerticalPadding, 0)); |
| 130 } | 122 } |
| 131 } | 123 } |
| 132 | 124 |
| 133 private: | 125 private: |
| 134 const int kShadowOffsetY = 2; | 126 const int kShadowOffsetY = 2; |
| 135 const int kShadowBlur = 2; | 127 const int kShadowBlur = 2; |
| 136 // TODO(fukino): Remove this constant once we stop maintaining pre-MD design. | |
| 137 // crbug.com/614453. | |
| 138 const int kContentsBetweenChildSpacingNonMd = 1; | |
| 139 | 128 |
| 140 // A structure that keeps the original offset of each header between the | 129 // A structure that keeps the original offset of each header between the |
| 141 // calls to Layout() to allow keeping track of which view should be sticky. | 130 // calls to Layout() to allow keeping track of which view should be sticky. |
| 142 struct Header { | 131 struct Header { |
| 143 explicit Header(views::View* view) | 132 explicit Header(views::View* view) |
| 144 : view(view), natural_offset(view->y()), draw_separator_below(false) {} | 133 : view(view), natural_offset(view->y()), draw_separator_below(false) {} |
| 145 | 134 |
| 146 // A header View that can be decorated as sticky. | 135 // A header View that can be decorated as sticky. |
| 147 views::View* view; | 136 views::View* view; |
| 148 | 137 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 213 } |
| 225 | 214 |
| 226 views::BoxLayout* box_layout_; | 215 views::BoxLayout* box_layout_; |
| 227 | 216 |
| 228 // Header child views that stick to the top of visible viewport when scrolled. | 217 // Header child views that stick to the top of visible viewport when scrolled. |
| 229 std::vector<Header> headers_; | 218 std::vector<Header> headers_; |
| 230 | 219 |
| 231 DISALLOW_COPY_AND_ASSIGN(ScrollContentsView); | 220 DISALLOW_COPY_AND_ASSIGN(ScrollContentsView); |
| 232 }; | 221 }; |
| 233 | 222 |
| 234 // Constants for the title row in material design. | 223 // Constants for the title row. |
| 235 const int kTitleRowVerticalPadding = 4; | 224 const int kTitleRowVerticalPadding = 4; |
| 236 const int kTitleRowProgressBarHeight = 2; | 225 const int kTitleRowProgressBarHeight = 2; |
| 237 const int kTitleRowPaddingTop = kTitleRowVerticalPadding; | 226 const int kTitleRowPaddingTop = kTitleRowVerticalPadding; |
| 238 const int kTitleRowPaddingBottom = | 227 const int kTitleRowPaddingBottom = |
| 239 kTitleRowVerticalPadding - kTitleRowProgressBarHeight; | 228 kTitleRowVerticalPadding - kTitleRowProgressBarHeight; |
| 240 | 229 |
| 241 class ScrollSeparator : public views::View { | 230 class ScrollSeparator : public views::View { |
| 242 public: | 231 public: |
| 243 ScrollSeparator() {} | 232 ScrollSeparator() {} |
| 244 | 233 |
| 245 ~ScrollSeparator() override {} | 234 ~ScrollSeparator() override {} |
| 246 | 235 |
| 247 private: | 236 private: |
| 248 // views::View: | 237 // views::View: |
| 249 void OnPaint(gfx::Canvas* canvas) override { | 238 void OnPaint(gfx::Canvas* canvas) override { |
| 250 canvas->FillRect(gfx::Rect(0, height() / 2, width(), 1), kBorderLightColor); | 239 canvas->FillRect(gfx::Rect(0, height() / 2, width(), 1), kBorderLightColor); |
| 251 } | 240 } |
| 252 gfx::Size GetPreferredSize() const override { | 241 gfx::Size GetPreferredSize() const override { |
| 253 return gfx::Size(1, kTrayPopupScrollSeparatorHeight); | 242 return gfx::Size(1, kTrayPopupScrollSeparatorHeight); |
| 254 } | 243 } |
| 255 | 244 |
| 256 DISALLOW_COPY_AND_ASSIGN(ScrollSeparator); | 245 DISALLOW_COPY_AND_ASSIGN(ScrollSeparator); |
| 257 }; | 246 }; |
| 258 | 247 |
| 259 } // namespace | 248 } // namespace |
| 260 | 249 |
| 261 class ScrollBorder : public views::Border { | |
| 262 public: | |
| 263 ScrollBorder() {} | |
| 264 ~ScrollBorder() override {} | |
| 265 | |
| 266 void set_visible(bool visible) { visible_ = visible; } | |
| 267 | |
| 268 private: | |
| 269 // views::Border: | |
| 270 void Paint(const views::View& view, gfx::Canvas* canvas) override { | |
| 271 if (!visible_) | |
| 272 return; | |
| 273 canvas->FillRect(gfx::Rect(0, view.height() - 1, view.width(), 1), | |
| 274 kBorderLightColor); | |
| 275 } | |
| 276 | |
| 277 gfx::Insets GetInsets() const override { return gfx::Insets(0, 0, 1, 0); } | |
| 278 | |
| 279 gfx::Size GetMinimumSize() const override { return gfx::Size(0, 1); } | |
| 280 | |
| 281 bool visible_ = false; | |
| 282 | |
| 283 DISALLOW_COPY_AND_ASSIGN(ScrollBorder); | |
| 284 }; | |
| 285 | |
| 286 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) | 250 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) |
| 287 : owner_(owner), | 251 : owner_(owner), |
| 288 box_layout_(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)), | 252 box_layout_(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)), |
| 289 title_row_(nullptr), | |
| 290 scroller_(nullptr), | 253 scroller_(nullptr), |
| 291 scroll_content_(nullptr), | 254 scroll_content_(nullptr), |
| 292 progress_bar_(nullptr), | 255 progress_bar_(nullptr), |
| 293 scroll_border_(nullptr), | |
| 294 tri_view_(nullptr), | 256 tri_view_(nullptr), |
| 295 back_button_(nullptr) { | 257 back_button_(nullptr) { |
| 296 SetLayoutManager(box_layout_); | 258 SetLayoutManager(box_layout_); |
| 297 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 259 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 298 } | 260 } |
| 299 | 261 |
| 300 TrayDetailsView::~TrayDetailsView() {} | 262 TrayDetailsView::~TrayDetailsView() {} |
| 301 | 263 |
| 302 void TrayDetailsView::OnViewClicked(views::View* sender) { | 264 void TrayDetailsView::OnViewClicked(views::View* sender) { |
| 303 if (!UseMd() && title_row_ && sender == title_row_->content()) { | |
| 304 TransitionToDefaultView(); | |
| 305 return; | |
| 306 } | |
| 307 | |
| 308 HandleViewClicked(sender); | 265 HandleViewClicked(sender); |
| 309 } | 266 } |
| 310 | 267 |
| 311 void TrayDetailsView::ButtonPressed(views::Button* sender, | 268 void TrayDetailsView::ButtonPressed(views::Button* sender, |
| 312 const ui::Event& event) { | 269 const ui::Event& event) { |
| 313 if (UseMd() && sender == back_button_) { | 270 if (sender == back_button_) { |
| 314 TransitionToDefaultView(); | 271 TransitionToDefaultView(); |
| 315 return; | 272 return; |
| 316 } | 273 } |
| 317 | 274 |
| 318 HandleButtonPressed(sender, event); | 275 HandleButtonPressed(sender, event); |
| 319 } | 276 } |
| 320 | 277 |
| 321 void TrayDetailsView::CreateTitleRow(int string_id) { | 278 void TrayDetailsView::CreateTitleRow(int string_id) { |
| 322 DCHECK(!tri_view_); | 279 DCHECK(!tri_view_); |
| 323 DCHECK(!title_row_); | |
| 324 | 280 |
| 325 if (UseMd()) { | 281 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); |
| 326 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); | |
| 327 | 282 |
| 328 back_button_ = CreateBackButton(); | 283 back_button_ = CreateBackButton(); |
| 329 tri_view_->AddView(TriView::Container::START, back_button_); | 284 tri_view_->AddView(TriView::Container::START, back_button_); |
| 330 | 285 |
| 331 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 286 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 332 auto* label = TrayPopupUtils::CreateDefaultLabel(); | 287 auto* label = TrayPopupUtils::CreateDefaultLabel(); |
| 333 label->SetText(rb.GetLocalizedString(string_id)); | 288 label->SetText(rb.GetLocalizedString(string_id)); |
| 334 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::TITLE); | 289 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::TITLE); |
| 335 style.SetupLabel(label); | 290 style.SetupLabel(label); |
| 336 tri_view_->AddView(TriView::Container::CENTER, label); | 291 tri_view_->AddView(TriView::Container::CENTER, label); |
| 337 | 292 |
| 338 tri_view_->SetContainerVisible(TriView::Container::END, false); | 293 tri_view_->SetContainerVisible(TriView::Container::END, false); |
| 339 | 294 |
| 340 tri_view_->SetBorder(views::CreateEmptyBorder(kTitleRowPaddingTop, 0, | 295 tri_view_->SetBorder(views::CreateEmptyBorder(kTitleRowPaddingTop, 0, |
| 341 kTitleRowPaddingBottom, 0)); | 296 kTitleRowPaddingBottom, 0)); |
| 342 AddChildViewAt(tri_view_, 0); | 297 AddChildViewAt(tri_view_, 0); |
| 343 views::Separator* separator = new views::Separator(); | 298 views::Separator* separator = new views::Separator(); |
| 344 separator->SetColor(kMenuSeparatorColor); | 299 separator->SetColor(kMenuSeparatorColor); |
| 345 separator->SetBorder(views::CreateEmptyBorder( | 300 separator->SetBorder(views::CreateEmptyBorder( |
| 346 kTitleRowProgressBarHeight - views::Separator::kThickness, 0, 0, 0)); | 301 kTitleRowProgressBarHeight - views::Separator::kThickness, 0, 0, 0)); |
| 347 AddChildViewAt(separator, kTitleRowSeparatorIndex); | 302 AddChildViewAt(separator, kTitleRowSeparatorIndex); |
| 348 } else { | |
| 349 title_row_ = new SpecialPopupRow(); | |
| 350 title_row_->SetTextLabel(string_id, this); | |
| 351 AddChildViewAt(title_row_, child_count()); | |
| 352 } | |
| 353 | 303 |
| 354 CreateExtraTitleRowButtons(); | 304 CreateExtraTitleRowButtons(); |
| 355 Layout(); | 305 Layout(); |
| 356 } | 306 } |
| 357 | 307 |
| 358 void TrayDetailsView::CreateScrollableList() { | 308 void TrayDetailsView::CreateScrollableList() { |
| 359 DCHECK(!scroller_); | 309 DCHECK(!scroller_); |
| 360 scroll_content_ = new ScrollContentsView(); | 310 scroll_content_ = new ScrollContentsView(); |
| 361 scroller_ = new views::ScrollView; | 311 scroller_ = new views::ScrollView; |
| 362 scroller_->SetContents(scroll_content_); | 312 scroller_->SetContents(scroll_content_); |
| 363 // Make the |scroller_| have a layer to clip |scroll_content_|'s children. | 313 // Make the |scroller_| have a layer to clip |scroll_content_|'s children. |
| 364 // TODO(varkha): Make the sticky rows work with EnableViewPortLayer(). | 314 // TODO(varkha): Make the sticky rows work with EnableViewPortLayer(). |
| 365 scroller_->SetPaintToLayer(); | 315 scroller_->SetPaintToLayer(); |
| 366 scroller_->set_background( | 316 scroller_->set_background( |
| 367 views::Background::CreateSolidBackground(kBackgroundColor)); | 317 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 368 scroller_->layer()->SetMasksToBounds(true); | 318 scroller_->layer()->SetMasksToBounds(true); |
| 369 | 319 |
| 370 // Note: |scroller_| takes ownership of |scroll_border_|. | |
| 371 if (!UseMd()) { | |
| 372 // In MD, the scroller is always the last thing, so this border is | |
| 373 // unnecessary and reserves extra space we don't want. | |
| 374 scroll_border_ = new ScrollBorder; | |
| 375 scroller_->SetBorder(std::unique_ptr<views::Border>(scroll_border_)); | |
| 376 } | |
| 377 | |
| 378 AddChildView(scroller_); | 320 AddChildView(scroller_); |
| 379 box_layout_->SetFlexForView(scroller_, 1); | 321 box_layout_->SetFlexForView(scroller_, 1); |
| 380 } | 322 } |
| 381 | 323 |
| 382 void TrayDetailsView::AddScrollSeparator() { | 324 void TrayDetailsView::AddScrollSeparator() { |
| 383 DCHECK(scroll_content_); | 325 DCHECK(scroll_content_); |
| 384 // Do not draw the separator if it is the very first item | 326 // Do not draw the separator if it is the very first item |
| 385 // in the scrollable list. | 327 // in the scrollable list. |
| 386 if (scroll_content_->has_children()) | 328 if (scroll_content_->has_children()) |
| 387 scroll_content_->AddChildView(new ScrollSeparator); | 329 scroll_content_->AddChildView(new ScrollSeparator); |
| 388 } | 330 } |
| 389 | 331 |
| 390 void TrayDetailsView::Reset() { | 332 void TrayDetailsView::Reset() { |
| 391 RemoveAllChildViews(true); | 333 RemoveAllChildViews(true); |
| 392 title_row_ = nullptr; | |
| 393 scroller_ = nullptr; | 334 scroller_ = nullptr; |
| 394 scroll_content_ = nullptr; | 335 scroll_content_ = nullptr; |
| 395 progress_bar_ = nullptr; | 336 progress_bar_ = nullptr; |
| 396 back_button_ = nullptr; | 337 back_button_ = nullptr; |
| 397 tri_view_ = nullptr; | 338 tri_view_ = nullptr; |
| 398 } | 339 } |
| 399 | 340 |
| 400 void TrayDetailsView::ShowProgress(double value, bool visible) { | 341 void TrayDetailsView::ShowProgress(double value, bool visible) { |
| 401 DCHECK(UseMd()); | |
| 402 DCHECK(tri_view_); | 342 DCHECK(tri_view_); |
| 403 if (!progress_bar_) { | 343 if (!progress_bar_) { |
| 404 progress_bar_ = new views::ProgressBar(kTitleRowProgressBarHeight); | 344 progress_bar_ = new views::ProgressBar(kTitleRowProgressBarHeight); |
| 405 progress_bar_->SetVisible(false); | 345 progress_bar_->SetVisible(false); |
| 406 AddChildViewAt(progress_bar_, kTitleRowSeparatorIndex + 1); | 346 AddChildViewAt(progress_bar_, kTitleRowSeparatorIndex + 1); |
| 407 } | 347 } |
| 408 | 348 |
| 409 progress_bar_->SetValue(value); | 349 progress_bar_->SetValue(value); |
| 410 progress_bar_->SetVisible(visible); | 350 progress_bar_->SetVisible(visible); |
| 411 child_at(kTitleRowSeparatorIndex)->SetVisible(!visible); | 351 child_at(kTitleRowSeparatorIndex)->SetVisible(!visible); |
| 412 } | 352 } |
| 413 | 353 |
| 414 views::CustomButton* TrayDetailsView::CreateSettingsButton( | 354 views::CustomButton* TrayDetailsView::CreateSettingsButton( |
| 415 LoginStatus status, | 355 LoginStatus status, |
| 416 int setting_accessible_name_id) { | 356 int setting_accessible_name_id) { |
| 417 DCHECK(UseMd()); | |
| 418 SystemMenuButton* button = | 357 SystemMenuButton* button = |
| 419 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, | 358 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, |
| 420 kSystemMenuSettingsIcon, setting_accessible_name_id); | 359 kSystemMenuSettingsIcon, setting_accessible_name_id); |
| 421 if (!TrayPopupUtils::CanOpenWebUISettings(status)) | 360 if (!TrayPopupUtils::CanOpenWebUISettings(status)) |
| 422 button->SetEnabled(false); | 361 button->SetEnabled(false); |
| 423 return button; | 362 return button; |
| 424 } | 363 } |
| 425 | 364 |
| 426 views::CustomButton* TrayDetailsView::CreateHelpButton(LoginStatus status) { | 365 views::CustomButton* TrayDetailsView::CreateHelpButton(LoginStatus status) { |
| 427 DCHECK(UseMd()); | |
| 428 SystemMenuButton* button = | 366 SystemMenuButton* button = |
| 429 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, | 367 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, |
| 430 kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP); | 368 kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP); |
| 431 if (!TrayPopupUtils::CanOpenWebUISettings(status)) | 369 if (!TrayPopupUtils::CanOpenWebUISettings(status)) |
| 432 button->SetEnabled(false); | 370 button->SetEnabled(false); |
| 433 return button; | 371 return button; |
| 434 } | 372 } |
| 435 | 373 |
| 436 void TrayDetailsView::HandleViewClicked(views::View* view) { | 374 void TrayDetailsView::HandleViewClicked(views::View* view) { |
| 437 NOTREACHED(); | 375 NOTREACHED(); |
| 438 } | 376 } |
| 439 | 377 |
| 440 void TrayDetailsView::HandleButtonPressed(views::Button* sender, | 378 void TrayDetailsView::HandleButtonPressed(views::Button* sender, |
| 441 const ui::Event& event) { | 379 const ui::Event& event) { |
| 442 NOTREACHED(); | 380 NOTREACHED(); |
| 443 } | 381 } |
| 444 | 382 |
| 445 void TrayDetailsView::CreateExtraTitleRowButtons() {} | 383 void TrayDetailsView::CreateExtraTitleRowButtons() {} |
| 446 | 384 |
| 447 void TrayDetailsView::TransitionToDefaultView() { | 385 void TrayDetailsView::TransitionToDefaultView() { |
| 448 if (UseMd()) { | 386 if (back_button_ && back_button_->HasFocus()) |
| 449 if (back_button_ && back_button_->HasFocus()) | 387 owner_->set_restore_focus(true); |
| 450 owner_->set_restore_focus(true); | |
| 451 } else { | |
| 452 if (title_row_ && title_row_->content() && | |
| 453 title_row_->content()->HasFocus()) { | |
| 454 owner_->set_restore_focus(true); | |
| 455 } | |
| 456 DoTransitionToDefaultView(); | |
| 457 return; | |
| 458 } | |
| 459 | 388 |
| 460 transition_delay_timer_.Start( | 389 transition_delay_timer_.Start( |
| 461 FROM_HERE, | 390 FROM_HERE, |
| 462 base::TimeDelta::FromMilliseconds(kTrayDetailedViewTransitionDelayMs), | 391 base::TimeDelta::FromMilliseconds(kTrayDetailedViewTransitionDelayMs), |
| 463 this, &TrayDetailsView::DoTransitionToDefaultView); | 392 this, &TrayDetailsView::DoTransitionToDefaultView); |
| 464 } | 393 } |
| 465 | 394 |
| 466 void TrayDetailsView::DoTransitionToDefaultView() { | 395 void TrayDetailsView::DoTransitionToDefaultView() { |
| 467 // Cache pointer to owner in this function scope. TrayDetailsView will be | 396 // Cache pointer to owner in this function scope. TrayDetailsView will be |
| 468 // deleted after called ShowDefaultView. | 397 // deleted after called ShowDefaultView. |
| 469 SystemTrayItem* owner = owner_; | 398 SystemTrayItem* owner = owner_; |
| 470 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); | 399 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 471 owner->set_restore_focus(false); | 400 owner->set_restore_focus(false); |
| 472 } | 401 } |
| 473 | 402 |
| 474 views::Button* TrayDetailsView::CreateBackButton() { | 403 views::Button* TrayDetailsView::CreateBackButton() { |
| 475 DCHECK(UseMd()); | |
| 476 SystemMenuButton* button = new SystemMenuButton( | 404 SystemMenuButton* button = new SystemMenuButton( |
| 477 this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuArrowBackIcon, | 405 this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuArrowBackIcon, |
| 478 IDS_ASH_STATUS_TRAY_PREVIOUS_MENU); | 406 IDS_ASH_STATUS_TRAY_PREVIOUS_MENU); |
| 479 return button; | 407 return button; |
| 480 } | 408 } |
| 481 | 409 |
| 482 void TrayDetailsView::Layout() { | 410 void TrayDetailsView::Layout() { |
| 483 views::View::Layout(); | 411 views::View::Layout(); |
| 484 if (scroller_ && !scroller_->is_bounded()) | 412 if (scroller_ && !scroller_->is_bounded()) |
| 485 scroller_->ClipHeightTo(0, scroller_->height()); | 413 scroller_->ClipHeightTo(0, scroller_->height()); |
| 486 } | 414 } |
| 487 | 415 |
| 488 int TrayDetailsView::GetHeightForWidth(int width) const { | 416 int TrayDetailsView::GetHeightForWidth(int width) const { |
| 489 if (!UseMd() || bounds().IsEmpty()) | 417 if (bounds().IsEmpty()) |
| 490 return views::View::GetHeightForWidth(width); | 418 return views::View::GetHeightForWidth(width); |
| 491 | 419 |
| 492 // The height of the bubble that contains this detailed view is set to | 420 // The height of the bubble that contains this detailed view is set to |
| 493 // the preferred height of the default view, and that determines the | 421 // the preferred height of the default view, and that determines the |
| 494 // initial height of |this|. Always request to stay the same height. | 422 // initial height of |this|. Always request to stay the same height. |
| 495 return height(); | 423 return height(); |
| 496 } | 424 } |
| 497 | 425 |
| 498 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) { | |
| 499 if (scroll_border_) { | |
| 500 int index = GetIndexOf(scroller_); | |
| 501 if (index < child_count() - 1 && child_at(index + 1) != title_row_) | |
| 502 scroll_border_->set_visible(true); | |
| 503 else | |
| 504 scroll_border_->set_visible(false); | |
| 505 } | |
| 506 | |
| 507 views::View::OnPaintBorder(canvas); | |
| 508 } | |
| 509 | |
| 510 } // namespace ash | 426 } // namespace ash |
| OLD | NEW |