| 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/material_design/material_design_controller.h" | |
| 8 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | 7 #include "ash/common/system/tray/fixed_sized_scroll_view.h" |
| 9 #include "ash/common/system/tray/system_tray.h" | 8 #include "ash/common/system/tray/system_tray.h" |
| 10 #include "ash/common/system/tray/system_tray_item.h" | 9 #include "ash/common/system/tray/system_tray_item.h" |
| 11 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
| 12 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 13 #include "ui/views/background.h" | 12 #include "ui/views/background.h" |
| 14 #include "ui/views/border.h" | 13 #include "ui/views/border.h" |
| 15 #include "ui/views/controls/scroll_view.h" | 14 #include "ui/views/controls/scroll_view.h" |
| 16 #include "ui/views/layout/box_layout.h" | 15 #include "ui/views/layout/box_layout.h" |
| 17 | 16 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 54 |
| 56 gfx::Size GetMinimumSize() const override { return gfx::Size(0, 1); } | 55 gfx::Size GetMinimumSize() const override { return gfx::Size(0, 1); } |
| 57 | 56 |
| 58 bool visible_; | 57 bool visible_; |
| 59 | 58 |
| 60 DISALLOW_COPY_AND_ASSIGN(ScrollBorder); | 59 DISALLOW_COPY_AND_ASSIGN(ScrollBorder); |
| 61 }; | 60 }; |
| 62 | 61 |
| 63 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) | 62 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) |
| 64 : owner_(owner), | 63 : owner_(owner), |
| 65 title_row_(nullptr), | 64 footer_(NULL), |
| 66 scroller_(nullptr), | 65 scroller_(NULL), |
| 67 scroll_content_(nullptr), | 66 scroll_content_(NULL), |
| 68 scroll_border_(nullptr) { | 67 scroll_border_(NULL) { |
| 69 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 68 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 70 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 69 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 71 } | 70 } |
| 72 | 71 |
| 73 TrayDetailsView::~TrayDetailsView() {} | 72 TrayDetailsView::~TrayDetailsView() {} |
| 74 | 73 |
| 75 void TrayDetailsView::OnViewClicked(views::View* sender) { | 74 void TrayDetailsView::CreateSpecialRow(int string_id, |
| 76 if (sender == title_row_->content()) | 75 ViewClickListener* listener) { |
| 77 TransitionToDefaultView(); | 76 DCHECK(!footer_); |
| 78 else | 77 footer_ = new SpecialPopupRow(); |
| 79 HandleViewClicked(sender); | 78 footer_->SetTextLabel(string_id, listener); |
| 80 } | 79 AddChildViewAt(footer_, child_count()); |
| 81 | |
| 82 void TrayDetailsView::ButtonPressed(views::Button* sender, | |
| 83 const ui::Event& event) { | |
| 84 // TODO(tdanderson): Handle presses for material design buttons common to all | |
| 85 // detailed views here (back and Settings). See crbug.com/642136. | |
| 86 HandleButtonPressed(sender, event); | |
| 87 } | |
| 88 | |
| 89 void TrayDetailsView::CreateTitleRow(int string_id) { | |
| 90 DCHECK(!title_row_); | |
| 91 const int child_view_position = | |
| 92 MaterialDesignController::IsSystemTrayMenuMaterial() ? 0 : child_count(); | |
| 93 title_row_ = new SpecialPopupRow(); | |
| 94 title_row_->SetTextLabel(string_id, this); | |
| 95 AddChildViewAt(title_row_, child_view_position); | |
| 96 CreateExtraTitleRowButtons(); | |
| 97 } | 80 } |
| 98 | 81 |
| 99 void TrayDetailsView::CreateScrollableList() { | 82 void TrayDetailsView::CreateScrollableList() { |
| 100 DCHECK(!scroller_); | 83 DCHECK(!scroller_); |
| 101 scroll_content_ = new views::View; | 84 scroll_content_ = new views::View; |
| 102 scroll_content_->SetLayoutManager( | 85 scroll_content_->SetLayoutManager( |
| 103 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | 86 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
| 104 scroller_ = new FixedSizedScrollView; | 87 scroller_ = new FixedSizedScrollView; |
| 105 scroller_->SetContentsView(scroll_content_); | 88 scroller_->SetContentsView(scroll_content_); |
| 106 | 89 |
| 107 // Note: |scroller_| takes ownership of |scroll_border_|. | 90 // Note: |scroller_| takes ownership of |scroll_border_|. |
| 108 scroll_border_ = new ScrollBorder; | 91 scroll_border_ = new ScrollBorder; |
| 109 scroller_->SetBorder(std::unique_ptr<views::Border>(scroll_border_)); | 92 scroller_->SetBorder(std::unique_ptr<views::Border>(scroll_border_)); |
| 110 | 93 |
| 111 AddChildView(scroller_); | 94 AddChildView(scroller_); |
| 112 } | 95 } |
| 113 | 96 |
| 114 void TrayDetailsView::AddScrollSeparator() { | 97 void TrayDetailsView::AddScrollSeparator() { |
| 115 DCHECK(scroll_content_); | 98 DCHECK(scroll_content_); |
| 116 // Do not draw the separator if it is the very first item | 99 // Do not draw the separator if it is the very first item |
| 117 // in the scrollable list. | 100 // in the scrollable list. |
| 118 if (scroll_content_->has_children()) | 101 if (scroll_content_->has_children()) |
| 119 scroll_content_->AddChildView(new ScrollSeparator); | 102 scroll_content_->AddChildView(new ScrollSeparator); |
| 120 } | 103 } |
| 121 | 104 |
| 122 void TrayDetailsView::Reset() { | 105 void TrayDetailsView::Reset() { |
| 123 RemoveAllChildViews(true); | 106 RemoveAllChildViews(true); |
| 124 title_row_ = nullptr; | 107 footer_ = NULL; |
| 125 scroller_ = nullptr; | 108 scroller_ = NULL; |
| 126 scroll_content_ = nullptr; | 109 scroll_content_ = NULL; |
| 127 } | 110 } |
| 128 | 111 |
| 129 void TrayDetailsView::HandleViewClicked(views::View* view) {} | |
| 130 | |
| 131 void TrayDetailsView::HandleButtonPressed(views::Button* sender, | |
| 132 const ui::Event& event) {} | |
| 133 | |
| 134 void TrayDetailsView::CreateExtraTitleRowButtons() {} | |
| 135 | |
| 136 void TrayDetailsView::TransitionToDefaultView() { | 112 void TrayDetailsView::TransitionToDefaultView() { |
| 137 // Cache pointer to owner in this function scope. TrayDetailsView will be | 113 // Cache pointer to owner in this function scope. TrayDetailsView will be |
| 138 // deleted after called ShowDefaultView. | 114 // deleted after called ShowDefaultView. |
| 139 SystemTrayItem* owner = owner_; | 115 SystemTrayItem* owner = owner_; |
| 140 if (title_row_ && title_row_->content() && title_row_->content()->HasFocus()) | 116 if (footer_ && footer_->content() && footer_->content()->HasFocus()) |
| 141 owner->set_restore_focus(true); | 117 owner->set_restore_focus(true); |
| 142 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); | 118 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
| 143 owner->set_restore_focus(false); | 119 owner->set_restore_focus(false); |
| 144 } | 120 } |
| 145 | 121 |
| 146 void TrayDetailsView::Layout() { | 122 void TrayDetailsView::Layout() { |
| 147 if (bounds().IsEmpty()) { | 123 if (bounds().IsEmpty()) { |
| 148 views::View::Layout(); | 124 views::View::Layout(); |
| 149 return; | 125 return; |
| 150 } | 126 } |
| 151 | 127 |
| 152 if (scroller_) { | 128 if (scroller_) { |
| 153 scroller_->set_fixed_size(gfx::Size()); | 129 scroller_->set_fixed_size(gfx::Size()); |
| 154 gfx::Size size = GetPreferredSize(); | 130 gfx::Size size = GetPreferredSize(); |
| 155 | 131 |
| 156 // Set the scroller to fill the space above the bottom row, so that the | 132 // Set the scroller to fill the space above the bottom row, so that the |
| 157 // bottom row of the detailed view will always stay just above the title | 133 // bottom row of the detailed view will always stay just above the footer. |
| 158 // row. | |
| 159 gfx::Size scroller_size = scroll_content_->GetPreferredSize(); | 134 gfx::Size scroller_size = scroll_content_->GetPreferredSize(); |
| 160 scroller_->set_fixed_size( | 135 scroller_->set_fixed_size( |
| 161 gfx::Size(width() + scroller_->GetScrollBarWidth(), | 136 gfx::Size(width() + scroller_->GetScrollBarWidth(), |
| 162 scroller_size.height() - (size.height() - height()))); | 137 scroller_size.height() - (size.height() - height()))); |
| 163 } | 138 } |
| 164 | 139 |
| 165 views::View::Layout(); | 140 views::View::Layout(); |
| 166 | 141 |
| 167 if (title_row_ && !MaterialDesignController::IsSystemTrayMenuMaterial()) { | 142 if (footer_) { |
| 168 // Always make sure the title row is bottom-aligned in non-MD. | 143 // Always make sure the footer element is bottom aligned. |
| 169 gfx::Rect fbounds = title_row_->bounds(); | 144 gfx::Rect fbounds = footer_->bounds(); |
| 170 fbounds.set_y(height() - title_row_->height()); | 145 fbounds.set_y(height() - footer_->height()); |
| 171 title_row_->SetBoundsRect(fbounds); | 146 footer_->SetBoundsRect(fbounds); |
| 172 } | 147 } |
| 173 } | 148 } |
| 174 | 149 |
| 175 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) { | 150 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) { |
| 176 if (scroll_border_) { | 151 if (scroll_border_) { |
| 177 int index = GetIndexOf(scroller_); | 152 int index = GetIndexOf(scroller_); |
| 178 if (index < child_count() - 1 && child_at(index + 1) != title_row_) | 153 if (index < child_count() - 1 && child_at(index + 1) != footer_) |
| 179 scroll_border_->set_visible(true); | 154 scroll_border_->set_visible(true); |
| 180 else | 155 else |
| 181 scroll_border_->set_visible(false); | 156 scroll_border_->set_visible(false); |
| 182 } | 157 } |
| 183 | 158 |
| 184 views::View::OnPaintBorder(canvas); | 159 views::View::OnPaintBorder(canvas); |
| 185 } | 160 } |
| 186 | 161 |
| 187 } // namespace ash | 162 } // namespace ash |
| OLD | NEW |