Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: ash/common/system/tray/tray_details_view.cc

Issue 2289223002: Make TrayDetailsView a ViewClickListener and ButtonListener (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
varkha 2016/08/31 20:28:14 nit: no empty line.
tdanderson 2016/08/31 22:24:15 Done.
87 HandleButtonPressed(sender, event);
88 }
89
90 void TrayDetailsView::CreateTitleRow(int string_id,
91 ViewClickListener* listener) {
92 DCHECK(!title_row_);
93 const int child_view_position =
94 MaterialDesignController::IsSystemTrayMenuMaterial() ? 0 : child_count();
95 title_row_ = new SpecialPopupRow();
96 title_row_->SetTextLabel(string_id, listener);
97 AddChildViewAt(title_row_, child_view_position);
98 CreateExtraTitleRowButtons();
80 } 99 }
81 100
82 void TrayDetailsView::CreateScrollableList() { 101 void TrayDetailsView::CreateScrollableList() {
83 DCHECK(!scroller_); 102 DCHECK(!scroller_);
84 scroll_content_ = new views::View; 103 scroll_content_ = new views::View;
85 scroll_content_->SetLayoutManager( 104 scroll_content_->SetLayoutManager(
86 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); 105 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
87 scroller_ = new FixedSizedScrollView; 106 scroller_ = new FixedSizedScrollView;
88 scroller_->SetContentsView(scroll_content_); 107 scroller_->SetContentsView(scroll_content_);
89 108
90 // Note: |scroller_| takes ownership of |scroll_border_|. 109 // Note: |scroller_| takes ownership of |scroll_border_|.
91 scroll_border_ = new ScrollBorder; 110 scroll_border_ = new ScrollBorder;
92 scroller_->SetBorder(std::unique_ptr<views::Border>(scroll_border_)); 111 scroller_->SetBorder(std::unique_ptr<views::Border>(scroll_border_));
93 112
94 AddChildView(scroller_); 113 AddChildView(scroller_);
95 } 114 }
96 115
97 void TrayDetailsView::AddScrollSeparator() { 116 void TrayDetailsView::AddScrollSeparator() {
98 DCHECK(scroll_content_); 117 DCHECK(scroll_content_);
99 // Do not draw the separator if it is the very first item 118 // Do not draw the separator if it is the very first item
100 // in the scrollable list. 119 // in the scrollable list.
101 if (scroll_content_->has_children()) 120 if (scroll_content_->has_children())
102 scroll_content_->AddChildView(new ScrollSeparator); 121 scroll_content_->AddChildView(new ScrollSeparator);
103 } 122 }
104 123
105 void TrayDetailsView::Reset() { 124 void TrayDetailsView::Reset() {
106 RemoveAllChildViews(true); 125 RemoveAllChildViews(true);
107 footer_ = NULL; 126 title_row_ = nullptr;
108 scroller_ = NULL; 127 scroller_ = nullptr;
109 scroll_content_ = NULL; 128 scroll_content_ = nullptr;
110 } 129 }
111 130
131 void TrayDetailsView::HandleViewClicked(views::View* view) {}
132
133 void TrayDetailsView::HandleButtonPressed(views::Button* sender,
134 const ui::Event& event) {}
135
136 void TrayDetailsView::CreateExtraTitleRowButtons() {}
137
112 void TrayDetailsView::TransitionToDefaultView() { 138 void TrayDetailsView::TransitionToDefaultView() {
113 // Cache pointer to owner in this function scope. TrayDetailsView will be 139 // Cache pointer to owner in this function scope. TrayDetailsView will be
114 // deleted after called ShowDefaultView. 140 // deleted after called ShowDefaultView.
115 SystemTrayItem* owner = owner_; 141 SystemTrayItem* owner = owner_;
116 if (footer_ && footer_->content() && footer_->content()->HasFocus()) 142 if (title_row_ && title_row_->content() && title_row_->content()->HasFocus())
117 owner->set_restore_focus(true); 143 owner->set_restore_focus(true);
118 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); 144 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
119 owner->set_restore_focus(false); 145 owner->set_restore_focus(false);
120 } 146 }
121 147
122 void TrayDetailsView::Layout() { 148 void TrayDetailsView::Layout() {
123 if (bounds().IsEmpty()) { 149 if (bounds().IsEmpty()) {
124 views::View::Layout(); 150 views::View::Layout();
125 return; 151 return;
126 } 152 }
127 153
128 if (scroller_) { 154 if (scroller_) {
129 scroller_->set_fixed_size(gfx::Size()); 155 scroller_->set_fixed_size(gfx::Size());
130 gfx::Size size = GetPreferredSize(); 156 gfx::Size size = GetPreferredSize();
131 157
132 // Set the scroller to fill the space above the bottom row, so that the 158 // 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. 159 // bottom row of the detailed view will always stay just above the title
160 // row.
134 gfx::Size scroller_size = scroll_content_->GetPreferredSize(); 161 gfx::Size scroller_size = scroll_content_->GetPreferredSize();
135 scroller_->set_fixed_size( 162 scroller_->set_fixed_size(
136 gfx::Size(width() + scroller_->GetScrollBarWidth(), 163 gfx::Size(width() + scroller_->GetScrollBarWidth(),
137 scroller_size.height() - (size.height() - height()))); 164 scroller_size.height() - (size.height() - height())));
138 } 165 }
139 166
140 views::View::Layout(); 167 views::View::Layout();
141 168
142 if (footer_) { 169 if (title_row_ && !MaterialDesignController::IsSystemTrayMenuMaterial()) {
143 // Always make sure the footer element is bottom aligned. 170 // Always make sure the title row is bottom-aligned in non-MD.
144 gfx::Rect fbounds = footer_->bounds(); 171 gfx::Rect fbounds = title_row_->bounds();
145 fbounds.set_y(height() - footer_->height()); 172 fbounds.set_y(height() - title_row_->height());
146 footer_->SetBoundsRect(fbounds); 173 title_row_->SetBoundsRect(fbounds);
147 } 174 }
148 } 175 }
149 176
150 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) { 177 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) {
151 if (scroll_border_) { 178 if (scroll_border_) {
152 int index = GetIndexOf(scroller_); 179 int index = GetIndexOf(scroller_);
153 if (index < child_count() - 1 && child_at(index + 1) != footer_) 180 if (index < child_count() - 1 && child_at(index + 1) != title_row_)
154 scroll_border_->set_visible(true); 181 scroll_border_->set_visible(true);
155 else 182 else
156 scroll_border_->set_visible(false); 183 scroll_border_->set_visible(false);
157 } 184 }
158 185
159 views::View::OnPaintBorder(canvas); 186 views::View::OnPaintBorder(canvas);
160 } 187 }
161 188
162 } // namespace ash 189 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698