Commit 60d4167c authored by sadrul@chromium.org's avatar sadrul@chromium.org

ash uber tray: Make the user-card float a few pixels above the rest of the items.

BUG=110130
TEST=none

Review URL: https://chromiumcodereview.appspot.com/9585012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124900 0039d316-1c4b-4281-b951-d872f2087c98
parent 42463cfc
...@@ -123,6 +123,8 @@ ...@@ -123,6 +123,8 @@
'system/tray/system_tray_delegate.h', 'system/tray/system_tray_delegate.h',
'system/tray/system_tray_item.cc', 'system/tray/system_tray_item.cc',
'system/tray/system_tray_item.h', 'system/tray/system_tray_item.h',
'system/tray/tray_empty.cc',
'system/tray/tray_empty.h',
'system/user/login_status.h', 'system/user/login_status.h',
'system/user/tray_user.cc', 'system/user/tray_user.cc',
'system/user/tray_user.h', 'system/user/tray_user.h',
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ash/system/power/tray_power_date.h" #include "ash/system/power/tray_power_date.h"
#include "ash/system/tray/system_tray_delegate.h" #include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray.h"
#include "ash/system/tray/tray_empty.h"
#include "ash/system/user/tray_user.h" #include "ash/system/user/tray_user.h"
#include "ash/tooltips/tooltip_controller.h" #include "ash/tooltips/tooltip_controller.h"
#include "ash/wm/activation_controller.h" #include "ash/wm/activation_controller.h"
...@@ -439,6 +440,7 @@ void Shell::Init() { ...@@ -439,6 +440,7 @@ void Shell::Init() {
power_status_controller_ = tray_power_date; power_status_controller_ = tray_power_date;
tray_->AddTrayItem(new internal::TrayUser()); tray_->AddTrayItem(new internal::TrayUser());
tray_->AddTrayItem(new internal::TrayEmpty());
tray_->AddTrayItem(tray_power_date); tray_->AddTrayItem(tray_power_date);
tray_->AddTrayItem(tray_volume); tray_->AddTrayItem(tray_volume);
tray_->AddTrayItem(tray_brightness); tray_->AddTrayItem(tray_brightness);
......
...@@ -12,7 +12,11 @@ ...@@ -12,7 +12,11 @@
#include "ash/wm/shadow_types.h" #include "ash/wm/shadow_types.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/gfx/canvas.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/bubble/bubble_delegate.h" #include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
...@@ -21,8 +25,121 @@ ...@@ -21,8 +25,121 @@
namespace { namespace {
const int kTrayIconHeight = 50; const int kArrowHeight = 10;
const int kPadding = 5; const int kArrowWidth = 20;
const int kArrowPaddingFromRight = 20;
const int kShadowOffset = 3;
const int kShadowHeight = 3;
const SkColor kDarkColor = SkColorSetRGB(120, 120, 120);
const SkColor kLightColor = SkColorSetRGB(240, 240, 240);
const SkColor kBackgroundColor = SK_ColorWHITE;
const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0);
class SystemTrayBubbleBackground : public views::Background {
public:
explicit SystemTrayBubbleBackground(views::View* owner)
: owner_(owner) {
}
virtual ~SystemTrayBubbleBackground() {}
private:
// Overridden from views::Background.
virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
views::View* last_view = NULL;
for (int i = 0; i < owner_->child_count(); i++) {
views::View* v = owner_->child_at(i);
if (!v->background()) {
canvas->FillRect(v->bounds(), kBackgroundColor);
} else if (last_view) {
canvas->FillRect(gfx::Rect(v->x() + kShadowOffset, v->y(),
v->width() - kShadowOffset, kShadowHeight),
kShadowColor);
}
if (!v->border()) {
canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1),
gfx::Point(v->x() + v->width() + 1, v->y() - 1),
!last_view || last_view->border() ? kDarkColor : kLightColor);
canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1),
gfx::Point(v->x() - 1, v->y() + v->height() + 1),
kDarkColor);
canvas->DrawLine(gfx::Point(v->x() + v->width(), v->y() - 1),
gfx::Point(v->x() + v->width(), v->y() + v->height() + 1),
kDarkColor);
} else if (last_view && !last_view->border()) {
canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1),
gfx::Point(v->x() + v->width() + 1, v->y() - 1),
kDarkColor);
}
last_view = v;
}
}
views::View* owner_;
DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBackground);
};
class SystemTrayBubbleBorder : public views::Border {
public:
explicit SystemTrayBubbleBorder(views::View* owner)
: owner_(owner) {
}
virtual ~SystemTrayBubbleBorder() {}
private:
// Overridden from views::Border.
virtual void Paint(const views::View& view,
gfx::Canvas* canvas) const OVERRIDE {
// Draw a line first.
int x = 4;
int y = owner_->height() + 1;
canvas->DrawLine(gfx::Point(x, y),
gfx::Point(owner_->width() + x, y),
kDarkColor);
// Now, draw a shadow.
canvas->FillRect(gfx::Rect(x + kShadowOffset, y,
owner_->width() - kShadowOffset, kShadowHeight),
kShadowColor);
// Draw the arrow.
int left_base_x = owner_->width() - kArrowPaddingFromRight - kArrowWidth;
int left_base_y = y;
int tip_x = left_base_x + kArrowWidth / 2;
int tip_y = left_base_y + kArrowHeight;
SkPath path;
path.incReserve(4);
path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y));
path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y));
path.lineTo(SkIntToScalar(left_base_x + kArrowWidth),
SkIntToScalar(left_base_y));
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(kBackgroundColor);
canvas->GetSkCanvas()->drawPath(path, paint);
// Now the draw the outline.
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(kDarkColor);
canvas->GetSkCanvas()->drawPath(path, paint);
}
virtual void GetInsets(gfx::Insets* insets) const OVERRIDE {
insets->Set(0, 0, kArrowHeight, 0);
}
views::View* owner_;
DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder);
};
class SystemTrayBubble : public views::BubbleDelegateView { class SystemTrayBubble : public views::BubbleDelegateView {
public: public:
...@@ -51,7 +168,8 @@ class SystemTrayBubble : public views::BubbleDelegateView { ...@@ -51,7 +168,8 @@ class SystemTrayBubble : public views::BubbleDelegateView {
// Overridden from views::BubbleDelegateView. // Overridden from views::BubbleDelegateView.
virtual void Init() OVERRIDE { virtual void Init() OVERRIDE {
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
0, 0, 1)); 1, 1, 1));
set_background(new SystemTrayBubbleBackground(this));
ash::SystemTrayDelegate* delegate = ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->tray_delegate(); ash::Shell::GetInstance()->tray_delegate();
...@@ -61,12 +179,8 @@ class SystemTrayBubble : public views::BubbleDelegateView { ...@@ -61,12 +179,8 @@ class SystemTrayBubble : public views::BubbleDelegateView {
++it) { ++it) {
views::View* view = detailed_ ? (*it)->CreateDetailedView(login_status) : views::View* view = detailed_ ? (*it)->CreateDetailedView(login_status) :
(*it)->CreateDefaultView(login_status); (*it)->CreateDefaultView(login_status);
if (!view) if (view)
continue; AddChildView(view);
if (it != items_.begin())
view->set_border(views::Border::CreateSolidSidedBorder(
1, 0, 0, 0, SkColorSetARGB(25, 0, 0, 0)));
AddChildView(view);
} }
} }
...@@ -150,6 +264,9 @@ void SystemTray::ShowItems(std::vector<SystemTrayItem*>& items, bool detailed) { ...@@ -150,6 +264,9 @@ void SystemTray::ShowItems(std::vector<SystemTrayItem*>& items, bool detailed) {
CHECK(!popup_); CHECK(!popup_);
SystemTrayBubble* bubble = new SystemTrayBubble(this, items, detailed); SystemTrayBubble* bubble = new SystemTrayBubble(this, items, detailed);
popup_ = views::BubbleDelegateView::CreateBubble(bubble); popup_ = views::BubbleDelegateView::CreateBubble(bubble);
popup_->non_client_view()->frame_view()->set_background(NULL);
popup_->non_client_view()->frame_view()->set_border(
new SystemTrayBubbleBorder(bubble));
popup_->AddObserver(this); popup_->AddObserver(this);
bubble->Show(); bubble->Show();
} }
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/tray/tray_empty.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/view.h"
namespace ash {
namespace internal {
TrayEmpty::TrayEmpty() {}
TrayEmpty::~TrayEmpty() {}
views::View* TrayEmpty::CreateTrayView(user::LoginStatus status) {
return NULL;
}
views::View* TrayEmpty::CreateDefaultView(user::LoginStatus status) {
views::View* view = new views::View;
view->set_background(views::Background::CreateSolidBackground(
SkColorSetARGB(0, 0, 0, 0)));
view->set_border(views::Border::CreateEmptyBorder(10, 0, 0, 0));
view->SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
0, 0, 0));
return view;
}
views::View* TrayEmpty::CreateDetailedView(user::LoginStatus status) {
return NULL;
}
void TrayEmpty::DestroyTrayView() {}
void TrayEmpty::DestroyDefaultView() {}
void TrayEmpty::DestroyDetailedView() {}
} // namespace internal
} // namespace ash
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_TRAY_TRAY_EMPTY_H_
#define ASH_SYSTEM_TRAY_TRAY_EMPTY_H_
#pragma once
#include "ash/system/tray/system_tray_item.h"
namespace ash {
namespace internal {
class TrayEmpty : public SystemTrayItem {
public:
TrayEmpty();
virtual ~TrayEmpty();
private:
// Overridden from SystemTrayItem.
virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE;
virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE;
virtual void DestroyTrayView() OVERRIDE;
virtual void DestroyDefaultView() OVERRIDE;
virtual void DestroyDetailedView() OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(TrayEmpty);
};
} // namespace internal
} // namespace ash
#endif // ASH_SYSTEM_TRAY_TRAY_EMPTY_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment