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