forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PanelWindow and PanelLayoutManager to ash. (+ win fix)
This implements a sample implementation of a WidgetDelegateView (PanelWindow) and a LayoutManager to provide an initial out ash_shell must be run with --aura-panels to get the new behavior, since Chrome currently relies on existing behavior for wi BUG=98330 TEST=Run ash_shell --aura-panels to see a simple panel test implementation. Ensure panels work as expected in Chrome. Original Review URL: http://codereview.chromium.org/9104027 TBR=dslomov@chromium.org Review URL: http://codereview.chromium.org/9325051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120478 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
stevenjb@chromium.org
committed
Feb 4, 2012
1 parent
83b583e
commit 6b85493
Showing
11 changed files
with
447 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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/shell/panel_window.h" | ||
|
||
#include "ash/wm/toplevel_frame_view.h" | ||
#include "base/utf_string_conversions.h" | ||
#include "ui/aura/window.h" | ||
#include "ui/gfx/canvas.h" | ||
#include "ui/views/widget/widget.h" | ||
|
||
namespace { | ||
const int kMinWidth = 100; | ||
const int kMinHeight = 100; | ||
const int kDefaultWidth = 200; | ||
const int kDefaultHeight = 300; | ||
} | ||
|
||
namespace ash { | ||
|
||
// static | ||
views::Widget* PanelWindow::CreatePanelWindow(const gfx::Rect& rect) { | ||
PanelWindow* panel_window = new PanelWindow("Example Panel Window"); | ||
panel_window->params().bounds = rect; | ||
return panel_window->CreateWidget(); | ||
} | ||
|
||
PanelWindow::PanelWindow(const std::string& name) | ||
: name_(name), | ||
params_(views::Widget::InitParams::TYPE_PANEL) { | ||
params_.delegate = this; | ||
} | ||
|
||
PanelWindow::~PanelWindow() { | ||
} | ||
|
||
views::Widget* PanelWindow::CreateWidget() { | ||
views::Widget* widget = new views::Widget; | ||
|
||
if (params().bounds.width() == 0) | ||
params().bounds.set_width(kDefaultWidth); | ||
if (params().bounds.height() == 0) | ||
params().bounds.set_height(kDefaultHeight); | ||
|
||
widget->Init(params()); | ||
widget->GetNativeView()->SetName(name_); | ||
widget->Show(); | ||
|
||
return widget; | ||
} | ||
|
||
gfx::Size PanelWindow::GetPreferredSize() { | ||
return gfx::Size(kMinWidth, kMinHeight); | ||
} | ||
|
||
void PanelWindow::OnPaint(gfx::Canvas* canvas) { | ||
canvas->FillRect(GetLocalBounds(), SK_ColorGREEN); | ||
} | ||
|
||
string16 PanelWindow::GetWindowTitle() const { | ||
return ASCIIToUTF16(name_); | ||
} | ||
|
||
views::View* PanelWindow::GetContentsView() { | ||
return this; | ||
} | ||
|
||
bool PanelWindow::CanResize() const { | ||
return true; | ||
} | ||
|
||
bool PanelWindow::CanMaximize() const { | ||
return false; | ||
} | ||
|
||
views::NonClientFrameView* PanelWindow::CreateNonClientFrameView() { | ||
// TODO(stevenjb): Implement a custom frame view for panels. | ||
// For now, use the default frame view (views::CustomFrameView) | ||
// which implements close and resize for us. | ||
return NULL; | ||
} | ||
|
||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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_SHELL_PANEL_WINDOW_H_ | ||
#define ASH_SHELL_PANEL_WINDOW_H_ | ||
#pragma once | ||
|
||
#include "base/basictypes.h" | ||
#include "ui/aura/aura_export.h" | ||
#include "ui/views/widget/widget.h" | ||
#include "ui/views/widget/widget_delegate.h" | ||
|
||
namespace ash { | ||
|
||
// Example Class for panel windows (Widget::InitParams::TYPE_PANEL). | ||
// Instances of PanelWindow will get added to the PanelContainer top level | ||
// window which manages the panel layout through PanelLayoutManager. | ||
class PanelWindow : public views::WidgetDelegateView { | ||
public: | ||
explicit PanelWindow(const std::string& name); | ||
virtual ~PanelWindow(); | ||
|
||
// Creates the widget for the panel window using |params_|. | ||
views::Widget* CreateWidget(); | ||
|
||
const std::string& name() { return name_; } | ||
views::Widget::InitParams& params() { return params_; } | ||
|
||
// Creates a panel window and returns the associated widget. | ||
static views::Widget* CreatePanelWindow(const gfx::Rect& rect); | ||
|
||
private: | ||
// Overridden from views::View: | ||
virtual gfx::Size GetPreferredSize() OVERRIDE; | ||
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | ||
|
||
// Overridden from views::WidgetDelegate: | ||
virtual string16 GetWindowTitle() const OVERRIDE; | ||
virtual View* GetContentsView() OVERRIDE; | ||
virtual bool CanResize() const OVERRIDE; | ||
virtual bool CanMaximize() const OVERRIDE; | ||
virtual views::NonClientFrameView* CreateNonClientFrameView() OVERRIDE; | ||
|
||
std::string name_; | ||
views::Widget::InitParams params_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(PanelWindow); | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_SHELL_PANEL_WINDOW_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// 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/wm/panel_layout_manager.h" | ||
|
||
#include <algorithm> | ||
|
||
#include "ash/launcher/launcher.h" | ||
#include "ash/shell.h" | ||
#include "base/auto_reset.h" | ||
#include "ui/aura/root_window.h" | ||
#include "ui/aura/window.h" | ||
#include "ui/gfx/rect.h" | ||
#include "ui/views/widget/widget.h" | ||
|
||
namespace { | ||
const int kPanelMarginEdge = 4; | ||
const int kPanelMarginMiddle = 8; | ||
const float kMaxHeightFactor = .80f; | ||
const float kMaxWidthFactor = .50f; | ||
} | ||
|
||
namespace ash { | ||
namespace internal { | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// PanelLayoutManager public implementation: | ||
|
||
PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container) | ||
: panel_container_(panel_container), | ||
in_layout_(false) { | ||
DCHECK(panel_container); | ||
} | ||
|
||
PanelLayoutManager::~PanelLayoutManager() { | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// PanelLayoutManager, aura::LayoutManager implementation: | ||
|
||
void PanelLayoutManager::OnWindowResized() { | ||
Relayout(); | ||
} | ||
|
||
void PanelLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | ||
panel_windows_.push_back(child); | ||
Relayout(); | ||
} | ||
|
||
void PanelLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { | ||
PanelList::iterator found = | ||
std::find(panel_windows_.begin(), panel_windows_.end(), child); | ||
if (found != panel_windows_.end()) | ||
panel_windows_.erase(found); | ||
Relayout(); | ||
} | ||
|
||
void PanelLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | ||
bool visible) { | ||
Relayout(); | ||
} | ||
|
||
void PanelLayoutManager::SetChildBounds(aura::Window* child, | ||
const gfx::Rect& requested_bounds) { | ||
gfx::Rect bounds(requested_bounds); | ||
const gfx::Rect& max_bounds = panel_container_->GetRootWindow()->bounds(); | ||
const int max_width = max_bounds.width() * kMaxWidthFactor; | ||
const int max_height = max_bounds.height() * kMaxHeightFactor; | ||
if (bounds.width() > max_width) | ||
bounds.set_width(max_width); | ||
if (bounds.height() > max_height) | ||
bounds.set_height(max_height); | ||
SetChildBoundsDirect(child, bounds); | ||
Relayout(); | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// PanelLayoutManager private implementation: | ||
|
||
// This is a rough outline of a simple panel layout manager. | ||
void PanelLayoutManager::Relayout() { | ||
if (in_layout_) | ||
return; | ||
AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | ||
|
||
// Panels are currently laid out just above the launcher (if it exists), | ||
// otherwise at the bottom of the root window. | ||
int right, bottom; | ||
ash::Shell* shell = ash::Shell::GetInstance(); | ||
if (shell->launcher() && shell->launcher()->widget()->IsVisible()) { | ||
const gfx::Rect& bounds = | ||
shell->launcher()->widget()->GetWindowScreenBounds(); | ||
right = bounds.width() - 1 - kPanelMarginEdge; | ||
bottom = bounds.y() - 1; | ||
} else { | ||
const gfx::Rect& bounds = panel_container_->GetRootWindow()->bounds(); | ||
right = bounds.width() - 1 - kPanelMarginEdge; | ||
bottom = bounds.bottom() - 1; | ||
} | ||
|
||
// Layout the panel windows right to left. | ||
for (PanelList::iterator iter = panel_windows_.begin(); | ||
iter != panel_windows_.end(); ++iter) { | ||
aura::Window* panel_win = *iter; | ||
if (!panel_win->IsVisible()) | ||
continue; | ||
int x = right - panel_win->bounds().width(); | ||
int y = bottom - panel_win->bounds().height(); | ||
gfx::Rect bounds(x, y, | ||
panel_win->bounds().width(), panel_win->bounds().height()); | ||
SetChildBoundsDirect(panel_win, bounds); | ||
right = x - kPanelMarginMiddle; | ||
} | ||
} | ||
|
||
} // namespace internal | ||
} // namespace ash |
Oops, something went wrong.