cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ash / system / tray / tray_details_view.cc
blob6e0a5607dabca698e35b0727c45372dd04e86cbd
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
3 // found in the LICENSE file.
5 #include "ash/system/tray/tray_details_view.h"
7 #include "ash/system/tray/fixed_sized_scroll_view.h"
8 #include "ash/system/tray/system_tray.h"
9 #include "ash/system/tray/system_tray_item.h"
10 #include "ash/system/tray/tray_constants.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/views/background.h"
13 #include "ui/views/border.h"
14 #include "ui/views/controls/scroll_view.h"
15 #include "ui/views/layout/box_layout.h"
17 namespace ash {
19 class ScrollSeparator : public views::View {
20 public:
21 ScrollSeparator() {}
23 ~ScrollSeparator() override {}
25 private:
26 // Overriden from views::View.
27 void OnPaint(gfx::Canvas* canvas) override {
28 canvas->FillRect(gfx::Rect(0, height() / 2, width(), 1), kBorderLightColor);
30 gfx::Size GetPreferredSize() const override {
31 return gfx::Size(1, kTrayPopupScrollSeparatorHeight);
34 DISALLOW_COPY_AND_ASSIGN(ScrollSeparator);
37 class ScrollBorder : public views::Border {
38 public:
39 ScrollBorder() {}
40 ~ScrollBorder() override {}
42 void set_visible(bool visible) { visible_ = visible; }
44 private:
45 // Overridden from views::Border.
46 void Paint(const views::View& view, gfx::Canvas* canvas) override {
47 if (!visible_)
48 return;
49 canvas->FillRect(gfx::Rect(0, view.height() - 1, view.width(), 1),
50 kBorderLightColor);
53 gfx::Insets GetInsets() const override { return gfx::Insets(0, 0, 1, 0); }
55 gfx::Size GetMinimumSize() const override { return gfx::Size(0, 1); }
57 bool visible_;
59 DISALLOW_COPY_AND_ASSIGN(ScrollBorder);
62 TrayDetailsView::TrayDetailsView(SystemTrayItem* owner)
63 : owner_(owner),
64 footer_(NULL),
65 scroller_(NULL),
66 scroll_content_(NULL),
67 scroll_border_(NULL) {
68 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
69 0, 0, 0));
70 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
73 TrayDetailsView::~TrayDetailsView() {
76 void TrayDetailsView::CreateSpecialRow(int string_id,
77 ViewClickListener* listener) {
78 DCHECK(!footer_);
79 footer_ = new SpecialPopupRow();
80 footer_->SetTextLabel(string_id, listener);
81 AddChildViewAt(footer_, child_count());
84 void TrayDetailsView::CreateScrollableList() {
85 DCHECK(!scroller_);
86 scroll_content_ = new views::View;
87 scroll_content_->SetLayoutManager(new views::BoxLayout(
88 views::BoxLayout::kVertical, 0, 0, 1));
89 scroller_ = new FixedSizedScrollView;
90 scroller_->SetContentsView(scroll_content_);
92 // Note: |scroller_| takes ownership of |scroll_border_|.
93 scroll_border_ = new ScrollBorder;
94 scroller_->SetBorder(scoped_ptr<views::Border>(scroll_border_));
96 AddChildView(scroller_);
99 void TrayDetailsView::AddScrollSeparator() {
100 DCHECK(scroll_content_);
101 // Do not draw the separator if it is the very first item
102 // in the scrollable list.
103 if (scroll_content_->has_children())
104 scroll_content_->AddChildView(new ScrollSeparator);
107 void TrayDetailsView::Reset() {
108 RemoveAllChildViews(true);
109 footer_ = NULL;
110 scroller_ = NULL;
111 scroll_content_ = NULL;
114 void TrayDetailsView::TransitionToDefaultView() {
115 // Cache pointer to owner in this function scope. TrayDetailsView will be
116 // deleted after called ShowDefaultView.
117 SystemTrayItem* owner = owner_;
118 if (footer_ && footer_->content() && footer_->content()->HasFocus())
119 owner->set_restore_focus(true);
120 owner->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
121 owner->set_restore_focus(false);
124 void TrayDetailsView::Layout() {
125 if (bounds().IsEmpty()) {
126 views::View::Layout();
127 return;
130 if (scroller_) {
131 scroller_->set_fixed_size(gfx::Size());
132 gfx::Size size = GetPreferredSize();
134 // Set the scroller to fill the space above the bottom row, so that the
135 // bottom row of the detailed view will always stay just above the footer.
136 gfx::Size scroller_size = scroll_content_->GetPreferredSize();
137 scroller_->set_fixed_size(
138 gfx::Size(width() + scroller_->GetScrollBarWidth(),
139 scroller_size.height() - (size.height() - height())));
142 views::View::Layout();
144 if (footer_) {
145 // Always make sure the footer element is bottom aligned.
146 gfx::Rect fbounds = footer_->bounds();
147 fbounds.set_y(height() - footer_->height());
148 footer_->SetBoundsRect(fbounds);
152 void TrayDetailsView::OnPaintBorder(gfx::Canvas* canvas) {
153 if (scroll_border_) {
154 int index = GetIndexOf(scroller_);
155 if (index < child_count() - 1 && child_at(index + 1) != footer_)
156 scroll_border_->set_visible(true);
157 else
158 scroll_border_->set_visible(false);
161 views::View::OnPaintBorder(canvas);
164 } // namespace ash