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

Unified Diff: ash/wm/panel_layout_manager.cc

Issue 11363250: Allow Chrome apps to create Ash Panels (apps v2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback and add unit test for PanelLayoutManager minimize/restore Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: ash/wm/panel_layout_manager.cc
diff --git a/ash/wm/panel_layout_manager.cc b/ash/wm/panel_layout_manager.cc
index e1f600fb8df4fd8a425346e7cbe9528a56384434..bfbc3eb45aa2c8464576eae994c34ec4f9134cd7 100644
--- a/ash/wm/panel_layout_manager.cc
+++ b/ash/wm/panel_layout_manager.cc
@@ -11,6 +11,8 @@
#include "ash/shell.h"
#include "ash/wm/frame_painter.h"
#include "ash/wm/property_util.h"
+#include "ash/wm/window_animations.h"
+#include "ash/wm/window_util.h"
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
@@ -19,6 +21,7 @@
#include "third_party/skia/include/core/SkPath.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/aura_constants.h"
+#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/gfx/canvas.h"
@@ -33,8 +36,6 @@ namespace {
const int kPanelMarginEdge = 4;
const int kPanelMarginMiddle = 8;
-const int kMinimizedHeight = 24;
-
const float kMaxHeightFactor = .80f;
const float kMaxWidthFactor = .50f;
@@ -107,6 +108,7 @@ void PanelLayoutManager::StartDragging(aura::Window* panel) {
DCHECK(!dragged_panel_);
DCHECK(panel->parent() == panel_container_);
dragged_panel_ = panel;
+ Relayout();
}
void PanelLayoutManager::FinishDragging() {
@@ -124,28 +126,10 @@ void PanelLayoutManager::ToggleMinimize(aura::Window* panel) {
DCHECK(panel->parent() == panel_container_);
if (panel->GetProperty(aura::client::kShowStateKey) ==
ui::SHOW_STATE_MINIMIZED) {
- const gfx::Rect& old_bounds = panel->bounds();
panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
-
- gfx::Rect new_bounds(old_bounds);
- const gfx::Rect* restore_bounds = GetRestoreBoundsInScreen(panel);
- if (restore_bounds) {
- new_bounds.set_height(restore_bounds->height());
- new_bounds.set_y(old_bounds.bottom() - restore_bounds->height());
- SetChildBounds(panel, new_bounds);
- ClearRestoreBounds(panel);
- }
} else {
- const gfx::Rect& old_bounds = panel->bounds();
panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
- SetRestoreBoundsInParent(panel, old_bounds);
- SetChildBounds(panel,
- gfx::Rect(old_bounds.x(),
- old_bounds.bottom() - kMinimizedHeight,
- old_bounds.width(),
- kMinimizedHeight));
}
- Relayout();
}
////////////////////////////////////////////////////////////////////////////////
@@ -158,6 +142,7 @@ void PanelLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
if (child == callout_widget_->GetNativeWindow())
return;
panel_windows_.push_back(child);
+ child->AddObserver(this);
Relayout();
}
@@ -166,6 +151,7 @@ void PanelLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) {
std::find(panel_windows_.begin(), panel_windows_.end(), child);
if (found != panel_windows_.end())
panel_windows_.erase(found);
+ child->RemoveObserver(this);
if (dragged_panel_ == child)
dragged_panel_ = NULL;
@@ -227,6 +213,22 @@ void PanelLayoutManager::OnLauncherIconPositionsChanged() {
Relayout();
}
+/////////////////////////////////////////////////////////////////////////////
+// PanelLayoutManager, WindowObserver implementation:
+
+void PanelLayoutManager::OnWindowPropertyChanged(aura::Window* window,
+ const void* key,
+ intptr_t old) {
+ if (key != aura::client::kShowStateKey)
+ return;
+ ui::WindowShowState new_state =
+ window->GetProperty(aura::client::kShowStateKey);
+ if (new_state == ui::SHOW_STATE_MINIMIZED)
+ MinimizePanel(window);
+ else
+ RestorePanel(window);
+}
+
////////////////////////////////////////////////////////////////////////////////
// PanelLayoutManager, aura::client::ActivationChangeObserver implementation:
void PanelLayoutManager::OnWindowActivated(aura::Window* active,
@@ -239,9 +241,23 @@ void PanelLayoutManager::OnWindowActivated(aura::Window* active,
}
}
-
////////////////////////////////////////////////////////////////////////////////
// PanelLayoutManager private implementation:
+
+void PanelLayoutManager::MinimizePanel(aura::Window* panel) {
+ SetWindowVisibilityAnimationType(
+ panel, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
+ panel->Hide();
+ if (wm::IsActiveWindow(panel))
+ wm::DeactivateWindow(panel);
+ Relayout();
+}
+
+void PanelLayoutManager::RestorePanel(aura::Window* panel) {
+ panel->Show();
+ Relayout();
+}
+
void PanelLayoutManager::Relayout() {
if (!launcher_ || !launcher_->widget())
return;
@@ -268,7 +284,8 @@ void PanelLayoutManager::Relayout() {
if (icon_bounds.IsEmpty())
continue;
- if (panel->HasFocus()) {
+ if (panel->HasFocus() ||
+ panel->Contains(panel->GetFocusManager()->GetFocusedWindow())) {
DCHECK(!active_panel);
active_panel = panel;
}

Powered by Google App Engine
This is Rietveld 408576698