Skip to content

Commit

Permalink
Adds the option of aligning the launcher to the left or right. There
Browse files Browse the repository at this point in the history
is a ton of rough edges after this patch, but I don't want this patch
to get any bigger.

BUG=121962
TEST=covered by tests.
R=ben@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136312 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sky@chromium.org committed May 10, 2012
1 parent b0055b9 commit 5544450
Show file tree
Hide file tree
Showing 36 changed files with 691 additions and 188 deletions.
2 changes: 2 additions & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
'launcher/background_animator.h',
'launcher/launcher.cc',
'launcher/launcher.h',
'launcher/launcher_alignment_menu.cc',
'launcher/launcher_alignment_menu.h',
'launcher/launcher_button.cc',
'launcher/launcher_button.h',
'launcher/launcher_context_menu.cc',
Expand Down
12 changes: 12 additions & 0 deletions ash/ash_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ This file contains the strings for ash.
<message name="IDS_AURA_LAUNCHER_CONTEXT_MENU_AUTO_HIDE_NOT_MAXIMIZED" desc="Title of the menu item in the context menu for auto-hiding the launcher when the current window is not maximized">
Autohide launcher
</message>
<message name="IDS_AURA_LAUNCHER_CONTEXT_MENU_POSITION" desc="Title of the menu item in the context menu for aligning the launcher">
Launcher position
</message>
<message name="IDS_AURA_LAUNCHER_CONTEXT_MENU_ALIGN_BOTTOM" desc="Title of the menu item in the context menu for aligning the launcher to the bottom of the screen">
Bottom
</message>
<message name="IDS_AURA_LAUNCHER_CONTEXT_MENU_ALIGN_LEFT" desc="Title of the menu item in the context menu for aligning the launcher to the left of the screen">
Left
</message>
<message name="IDS_AURA_LAUNCHER_CONTEXT_MENU_ALIGN_RIGHT" desc="Title of the menu item in the context menu for aligning the launcher to the right of the screen">
Right
</message>

<message name="IDS_AURA_SET_DESKTOP_WALLPAPER" desc="The label used for change wallpaper in context menu">
Set wallpaper...
Expand Down
43 changes: 20 additions & 23 deletions ash/launcher/launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ class Launcher::DelegateView : public views::WidgetDelegate,
explicit DelegateView(Launcher* launcher);
virtual ~DelegateView();

void SetStatusWidth(int width);
int status_width() const { return status_width_; }

void set_focus_cycler(internal::FocusCycler* focus_cycler) {
focus_cycler_ = focus_cycler;
}
Expand All @@ -67,40 +64,33 @@ class Launcher::DelegateView : public views::WidgetDelegate,

private:
Launcher* launcher_;

// Width of the status area.
int status_width_;

internal::FocusCycler* focus_cycler_;

DISALLOW_COPY_AND_ASSIGN(DelegateView);
};

Launcher::DelegateView::DelegateView(Launcher* launcher)
: launcher_(launcher),
status_width_(0),
focus_cycler_(NULL) {
}

Launcher::DelegateView::~DelegateView() {
}

void Launcher::DelegateView::SetStatusWidth(int width) {
if (status_width_ == width)
return;

status_width_ = width;
Layout();
}

gfx::Size Launcher::DelegateView::GetPreferredSize() {
return child_count() > 0 ? child_at(0)->GetPreferredSize() : gfx::Size();
}

void Launcher::DelegateView::Layout() {
if (child_count() == 0)
return;
child_at(0)->SetBounds(0, 0, std::max(0, width() - status_width_), height());
if (launcher_->alignment_ == SHELF_ALIGNMENT_BOTTOM) {
int w = std::max(0, width() - launcher_->status_size_.width());
child_at(0)->SetBounds(0, 0, w, height());
} else {
int h = std::max(0, height() - launcher_->status_size_.height());
child_at(0)->SetBounds(0, 0, width(), h);
}
}

// Launcher --------------------------------------------------------------------
Expand All @@ -110,6 +100,7 @@ Launcher::Launcher(aura::Window* window_container)
window_container_(window_container),
delegate_view_(NULL),
launcher_view_(NULL),
alignment_(SHELF_ALIGNMENT_BOTTOM),
ALLOW_THIS_IN_INITIALIZER_LIST(
background_animator_(this, 0, kBackgroundAlpha)) {
model_.reset(new LauncherModel);
Expand All @@ -136,7 +127,7 @@ Launcher::Launcher(aura::Window* window_container)
widget_->GetNativeWindow()->SetName("LauncherWindow");
gfx::Size pref =
static_cast<views::View*>(launcher_view_)->GetPreferredSize();
widget_->SetBounds(gfx::Rect(0, 0, pref.width(), pref.height()));
widget_->SetBounds(gfx::Rect(pref));
// The launcher should not take focus when it is initially shown.
widget_->set_focus_on_creation(false);
widget_->SetContentsView(delegate_view_);
Expand All @@ -156,18 +147,24 @@ internal::FocusCycler* Launcher::GetFocusCycler() {
return delegate_view_->focus_cycler();
}

void Launcher::SetAlignment(ShelfAlignment alignment) {
alignment_ = alignment;
launcher_view_->SetAlignment(alignment);
// ShelfLayoutManager will resize the launcher.
}

void Launcher::SetPaintsBackground(
bool value,
internal::BackgroundAnimator::ChangeType change_type) {
background_animator_.SetPaintsBackground(value, change_type);
}

void Launcher::SetStatusWidth(int width) {
delegate_view_->SetStatusWidth(width);
}
void Launcher::SetStatusSize(const gfx::Size& size) {
if (status_size_ == size)
return;

int Launcher::GetStatusWidth() {
return delegate_view_->status_width();
status_size_ = size;
delegate_view_->Layout();
}

gfx::Rect Launcher::GetScreenBoundsOfItemIconForWindow(aura::Window* window) {
Expand Down
16 changes: 13 additions & 3 deletions ash/launcher/launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include "ash/ash_export.h"
#include "ash/launcher/background_animator.h"
#include "ash/launcher/launcher_types.h"
#include "ash/wm/shelf_auto_hide_behavior.h"
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "ui/gfx/size.h"

namespace aura {
class Window;
Expand Down Expand Up @@ -45,15 +47,18 @@ class ASH_EXPORT Launcher : public internal::BackgroundAnimatorDelegate {
void SetFocusCycler(internal::FocusCycler* focus_cycler);
internal::FocusCycler* GetFocusCycler();

void SetAlignment(ShelfAlignment alignment);
ShelfAlignment alignment() const { return alignment_; }

// Sets whether the launcher paints a background. Default is false, but is set
// to true if a window overlaps the shelf.
void SetPaintsBackground(
bool value,
internal::BackgroundAnimator::ChangeType change_type);

// Sets the width of the status area.
void SetStatusWidth(int width);
int GetStatusWidth();
// Sets the size of the status area.
void SetStatusSize(const gfx::Size& size);
const gfx::Size& status_size() const { return status_size_; }

// Returns the screen bounds of the item for the specified window. If there is
// no item for the specified window an empty rect is returned.
Expand Down Expand Up @@ -104,8 +109,13 @@ class ASH_EXPORT Launcher : public internal::BackgroundAnimatorDelegate {
// LauncherView used to display icons.
internal::LauncherView* launcher_view_;

ShelfAlignment alignment_;

scoped_ptr<LauncherDelegate> delegate_;

// Size reserved for the status area.
gfx::Size status_size_;

// Used to animate the background.
internal::BackgroundAnimator background_animator_;

Expand Down
71 changes: 71 additions & 0 deletions ash/launcher/launcher_alignment_menu.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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/launcher/launcher_alignment_menu.h"

#include "ash/shell.h"
#include "ash/wm/shelf_auto_hide_behavior.h"
#include "grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"

namespace ash {

LauncherAlignmentMenu::LauncherAlignmentMenu() : ui::SimpleMenuModel(NULL) {
int align_group_id = 1;
set_delegate(this);
AddRadioItemWithStringId(MENU_ALIGN_LEFT,
IDS_AURA_LAUNCHER_CONTEXT_MENU_ALIGN_LEFT,
align_group_id);
AddRadioItemWithStringId(MENU_ALIGN_BOTTOM,
IDS_AURA_LAUNCHER_CONTEXT_MENU_ALIGN_BOTTOM,
align_group_id);
AddRadioItemWithStringId(MENU_ALIGN_RIGHT,
IDS_AURA_LAUNCHER_CONTEXT_MENU_ALIGN_RIGHT,
align_group_id);
}

LauncherAlignmentMenu::~LauncherAlignmentMenu() {
}

bool LauncherAlignmentMenu::IsCommandIdChecked(int command_id) const {
switch (command_id) {
case MENU_ALIGN_LEFT:
return ash::Shell::GetInstance()->GetShelfAlignment() ==
SHELF_ALIGNMENT_LEFT;
case MENU_ALIGN_BOTTOM:
return ash::Shell::GetInstance()->GetShelfAlignment() ==
SHELF_ALIGNMENT_BOTTOM;
case MENU_ALIGN_RIGHT:
return ash::Shell::GetInstance()->GetShelfAlignment() ==
SHELF_ALIGNMENT_RIGHT;
default:
return false;
}
}

bool LauncherAlignmentMenu::IsCommandIdEnabled(int command_id) const {
return true;
}

bool LauncherAlignmentMenu::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) {
return false;
}

void LauncherAlignmentMenu::ExecuteCommand(int command_id) {
switch (static_cast<MenuItem>(command_id)) {
case MENU_ALIGN_LEFT:
ash::Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT);
break;
case MENU_ALIGN_BOTTOM:
ash::Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM);
break;
case MENU_ALIGN_RIGHT:
ash::Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT);
break;
}
}

} // namespace ash
43 changes: 43 additions & 0 deletions ash/launcher/launcher_alignment_menu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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_WM_LAUNCHER_LAUNCHER_ALIGNMENT_MENU_H_
#define ASH_WM_LAUNCHER_LAUNCHER_ALIGNMENT_MENU_H_
#pragma once

#include "ash/ash_export.h"
#include "base/basictypes.h"
#include "ui/base/models/simple_menu_model.h"

namespace ash {

// Submenu for choosing the alignment of the launcher.
class ASH_EXPORT LauncherAlignmentMenu : public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate {
public:
LauncherAlignmentMenu();
virtual ~LauncherAlignmentMenu();

// ui::SimpleMenuModel::Delegate overrides:
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) OVERRIDE;
virtual void ExecuteCommand(int command_id) OVERRIDE;

private:
enum MenuItem {
// Offset so as not to interfere with other menus.
MENU_ALIGN_LEFT = 500,
MENU_ALIGN_RIGHT,
MENU_ALIGN_BOTTOM,
};

DISALLOW_COPY_AND_ASSIGN(LauncherAlignmentMenu);
};

} // namespace ash

#endif // ASH_WM_LAUNCHER_LAUNCHER_ALIGNMENT_MENU_H_
3 changes: 3 additions & 0 deletions ash/launcher/launcher_button_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include "ash/ash_export.h"
#include "ash/wm/shelf_auto_hide_behavior.h"
#include "base/string16.h"

namespace views {
Expand Down Expand Up @@ -36,6 +37,8 @@ class ASH_EXPORT LauncherButtonHost {
// Invoked when the mouse exits the item.
virtual void MouseExitedButton(views::View* view) = 0;

virtual ShelfAlignment GetShelfAlignment() const = 0;

// Invoked to get the accessible name of the item.
virtual string16 GetAccessibleName(const views::View* view) = 0;

Expand Down
6 changes: 6 additions & 0 deletions ash/launcher/launcher_context_menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ash/launcher/launcher_context_menu.h"

#include "ash/shell.h"
#include "ash/wm/shelf_auto_hide_behavior.h"
#include "grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"

Expand All @@ -13,6 +14,9 @@ namespace ash {
LauncherContextMenu::LauncherContextMenu() : ui::SimpleMenuModel(NULL) {
set_delegate(this);
AddCheckItemWithStringId(MENU_AUTO_HIDE, GetAutoHideResourceStringId());
AddSubMenuWithStringId(MENU_ALIGNMENT_MENU,
IDS_AURA_LAUNCHER_CONTEXT_MENU_POSITION,
&alignment_menu_);
}

LauncherContextMenu::~LauncherContextMenu() {
Expand Down Expand Up @@ -79,6 +83,8 @@ void LauncherContextMenu::ExecuteCommand(int command_id) {
ash::Shell::GetInstance()->SetShelfAutoHideBehavior(
GetToggledAutoHideBehavior());
break;
case MENU_ALIGNMENT_MENU:
break;
}
}

Expand Down
4 changes: 4 additions & 0 deletions ash/launcher/launcher_context_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include "ash/ash_export.h"
#include "ash/launcher/launcher_alignment_menu.h"
#include "ash/wm/shelf_auto_hide_behavior.h"
#include "base/basictypes.h"
#include "ui/base/models/simple_menu_model.h"
Expand Down Expand Up @@ -40,8 +41,11 @@ class ASH_EXPORT LauncherContextMenu : public ui::SimpleMenuModel,
private:
enum MenuItem {
MENU_AUTO_HIDE,
MENU_ALIGNMENT_MENU,
};

LauncherAlignmentMenu alignment_menu_;

DISALLOW_COPY_AND_ASSIGN(LauncherContextMenu);
};

Expand Down
2 changes: 1 addition & 1 deletion ash/launcher/launcher_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace ash {

const int kLauncherPreferredHeight = 48;
const int kLauncherPreferredSize = 48;

LauncherItem::LauncherItem()
: type(TYPE_TABBED),
Expand Down
2 changes: 1 addition & 1 deletion ash/launcher/launcher_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef int LauncherID;

// Height of the Launcher. Hard coded to avoid resizing as items are
// added/removed.
ASH_EXPORT extern const int kLauncherPreferredHeight;
ASH_EXPORT extern const int kLauncherPreferredSize;

// Type the LauncherItem represents.
enum ASH_EXPORT LauncherItemType {
Expand Down
9 changes: 5 additions & 4 deletions ash/launcher/launcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ using ash::internal::LauncherButton;

namespace ash {

// Makes sure invoking SetStatusWidth on the launcher changes the size of the
// Makes sure invoking SetStatusSize on the launcher changes the size of the
// LauncherView.
TEST_F(LauncherTest, SetStatusWidth) {
TEST_F(LauncherTest, SetStatusSize) {
Launcher* launcher = Shell::GetInstance()->launcher();
LauncherView* launcher_view = launcher->GetLauncherViewForTest();

int total_width = launcher->widget()->GetWindowScreenBounds().width();
gfx::Size launcher_size = launcher->widget()->GetWindowScreenBounds().size();
int total_width = launcher_size.width();
ASSERT_GT(total_width, 0);
launcher->SetStatusWidth(total_width / 2);
launcher->SetStatusSize(gfx::Size(total_width / 2, launcher_size.height()));
EXPECT_EQ(total_width - total_width / 2, launcher_view->width());
}

Expand Down
Loading

0 comments on commit 5544450

Please sign in to comment.