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

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

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

Powered by Google App Engine
This is Rietveld 408576698