Skip to content

Commit

Permalink
Revert of Only create DockedBackgroundWidget as needed. (patchset chr…
Browse files Browse the repository at this point in the history
…omium#6 id:100001 of https://codereview.chromium.org/1882713004/ )

Reason for revert:
Broke ash_unittests. More info in http://crbug.com/603419.

BUG=603419

Original issue's description:
> Only create DockedBackgroundWidget as needed.
>
> This util widget shows up as a user window shelf icon in mash.
> Don't create this widget until it's needed (not used in mash).
>
> We currently put kShellWindowId_DockedContainer windows in mash::wm::mojom::Container::USER_WINDOWS, which might be okay in the long run, but even if we put them in a separate container, we would need UserWindowControllerImpl to track that container's set of user windows (to show shelf icons); so we would need to single out this widget as a non-user-window somehow.
>
> We currently don't support docking in mash, but if we choose to use ash's DockedWindowLayoutManager (and DockedBackgroundWidget), we'll need to avoid tracking this background widget as a user window.
>
> BUG=NONE
> TEST="mojo_runner mojo:mash_session" doesn't show a mysterious shelf icon at startup.
> R=sky@chromium.org
>
> Committed: https://crrev.com/14816ec6589c41b5a34f7b534b1c1565c97fe2d7
> Cr-Commit-Position: refs/heads/master@{#387182}

TBR=sky@chromium.org,msw@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=NONE

Review URL: https://codereview.chromium.org/1888733002

Cr-Commit-Position: refs/heads/master@{#387259}
  • Loading branch information
vabr authored and Commit bot committed Apr 14, 2016
1 parent cb28948 commit bc758d4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 52 deletions.
101 changes: 49 additions & 52 deletions ash/wm/dock/docked_window_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_constants.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
#include "ash/shelf/shelf_types.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
Expand Down Expand Up @@ -58,8 +57,7 @@ const int kFadeDurationMs = 60;
const int kMinimizeDurationMs = 720;

class DockedBackgroundWidget : public views::Widget,
public BackgroundAnimatorDelegate,
public ShelfLayoutManagerObserver {
public BackgroundAnimatorDelegate {
public:
explicit DockedBackgroundWidget(aura::Window* container)
: alignment_(DOCKED_ALIGNMENT_NONE),
Expand All @@ -68,27 +66,27 @@ class DockedBackgroundWidget : public views::Widget,
opaque_background_(ui::LAYER_SOLID_COLOR),
visible_background_type_(SHELF_BACKGROUND_DEFAULT),
visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) {
Shelf* shelf = Shelf::ForWindow(container);
visible_background_type_ = shelf->shelf_widget()->GetBackgroundType();
shelf->shelf_layout_manager()->AddObserver(this);

InitWidget(container);
}

~DockedBackgroundWidget() override {
Shelf* shelf = Shelf::ForWindow(GetNativeWindow());
if (shelf && shelf->shelf_layout_manager())
shelf->shelf_layout_manager()->RemoveObserver(this);
}

// Sets widget bounds and sizes opaque background layer to fill the widget.
void SetBackgroundBounds(const gfx::Rect bounds, DockedAlignment alignment) {
SetBounds(bounds);
opaque_background_.SetBounds(gfx::Rect(bounds.size()));
alignment_ = alignment;
}

private:
// Sets the background type. Starts an animation to transition to
// |background_type| if the widget is visible. If the widget is not visible,
// the animation is postponed till the widget becomes visible.
void SetBackgroundType(ShelfBackgroundType background_type,
BackgroundAnimatorChangeType change_type) {
visible_background_type_ = background_type;
visible_background_change_type_ = change_type;
if (IsVisible())
UpdateBackground();
}

// views::Widget:
void OnNativeWidgetVisibilityChanged(bool visible) override {
views::Widget::OnNativeWidgetVisibilityChanged(visible);
Expand Down Expand Up @@ -126,18 +124,7 @@ class DockedBackgroundWidget : public views::Widget,
SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size()));
}

// ShelfLayoutManagerObserver:
void OnBackgroundUpdated(ShelfBackgroundType background_type,
BackgroundAnimatorChangeType change_type) override {
// Sets the background type. Starts an animation to transition to
// |background_type| if the widget is visible. If the widget is not visible,
// the animation is postponed till the widget becomes visible.
visible_background_type_ = background_type;
visible_background_change_type_ = change_type;
if (IsVisible())
UpdateBackground();
}

private:
void InitWidget(aura::Window* parent) {
views::Widget::InitParams params;
params.type = views::Widget::InitParams::TYPE_POPUP;
Expand All @@ -154,6 +141,7 @@ class DockedBackgroundWidget : public views::Widget,
opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size()));
opaque_background_.SetOpacity(0.0f);
GetNativeWindow()->layer()->Add(&opaque_background_);
Hide();

ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
gfx::ImageSkia shelf_background =
Expand All @@ -162,9 +150,6 @@ class DockedBackgroundWidget : public views::Widget,
shelf_background, SkBitmapOperations::ROTATION_90_CW);
shelf_background_right_ = gfx::ImageSkiaOperations::CreateRotatedImage(
shelf_background, SkBitmapOperations::ROTATION_270_CW);

// Stack the background below any windows already in the dock container.
parent->StackChildAtBottom(GetNativeWindow());
}

// Transitions to |visible_background_type_| if the widget is visible and to
Expand Down Expand Up @@ -416,20 +401,20 @@ DockedWindowLayoutManager::DockedWindowLayoutManager(
: SnapToPixelLayoutManager(dock_container),
dock_container_(dock_container),
in_layout_(false),
dragged_window_(nullptr),
dragged_window_(NULL),
is_dragged_window_docked_(false),
is_dragged_from_dock_(false),
shelf_(nullptr),
shelf_(NULL),
workspace_controller_(workspace_controller),
in_fullscreen_(workspace_controller_->GetWindowState() ==
WORKSPACE_WINDOW_STATE_FULL_SCREEN),
docked_width_(0),
alignment_(DOCKED_ALIGNMENT_NONE),
preferred_alignment_(DOCKED_ALIGNMENT_NONE),
event_source_(DOCKED_ACTION_SOURCE_UNKNOWN),
last_active_window_(nullptr),
last_active_window_(NULL),
last_action_time_(base::Time::Now()),
background_widget_(nullptr) {
background_widget_(new DockedBackgroundWidget(dock_container_)) {
DCHECK(dock_container);
aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())->
AddObserver(this);
Expand All @@ -441,9 +426,11 @@ DockedWindowLayoutManager::~DockedWindowLayoutManager() {
}

void DockedWindowLayoutManager::Shutdown() {
background_widget_.reset();
shelf_observer_.reset();
shelf_ = nullptr;
if (shelf_ && shelf_->shelf_layout_manager()) {
shelf_->shelf_layout_manager()->RemoveObserver(this);
shelf_observer_.reset();
}
shelf_ = NULL;
for (size_t i = 0; i < dock_container_->children().size(); ++i) {
aura::Window* child = dock_container_->children()[i];
child->RemoveObserver(this);
Expand Down Expand Up @@ -530,7 +517,7 @@ void DockedWindowLayoutManager::FinishDragging(DockedAction action,
dragged_window_->RemoveObserver(this);
wm::GetWindowState(dragged_window_)->RemoveObserver(this);
if (last_active_window_ == dragged_window_)
last_active_window_ = nullptr;
last_active_window_ = NULL;
} else {
// If this is the first window that got docked by a move update alignment.
if (alignment_ == DOCKED_ALIGNMENT_NONE)
Expand All @@ -541,7 +528,7 @@ void DockedWindowLayoutManager::FinishDragging(DockedAction action,
// count limit so do it here.
MaybeMinimizeChildrenExcept(dragged_window_);
}
dragged_window_ = nullptr;
dragged_window_ = NULL;
dragged_bounds_ = gfx::Rect();
Relayout();
UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED);
Expand All @@ -551,7 +538,10 @@ void DockedWindowLayoutManager::FinishDragging(DockedAction action,
void DockedWindowLayoutManager::SetShelf(Shelf* shelf) {
DCHECK(!shelf_);
shelf_ = shelf;
shelf_observer_.reset(new ShelfWindowObserver(this));
if (shelf_->shelf_layout_manager()) {
shelf_->shelf_layout_manager()->AddObserver(this);
shelf_observer_.reset(new ShelfWindowObserver(this));
}
}

DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow(
Expand Down Expand Up @@ -724,7 +714,7 @@ void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) {
UpdateDockedWidth(0);
}
if (last_active_window_ == child)
last_active_window_ = nullptr;
last_active_window_ = NULL;
child->RemoveObserver(this);
wm::GetWindowState(child)->RemoveObserver(this);
Relayout();
Expand Down Expand Up @@ -830,6 +820,14 @@ void DockedWindowLayoutManager::OnShelfAlignmentChanged(
UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED);
}

/////////////////////////////////////////////////////////////////////////////
// DockedWindowLayoutManager, ShelfLayoutManagerObserver implementation:
void DockedWindowLayoutManager::OnBackgroundUpdated(
ShelfBackgroundType background_type,
BackgroundAnimatorChangeType change_type) {
background_widget_->SetBackgroundType(background_type, change_type);
}

/////////////////////////////////////////////////////////////////////////////
// DockedWindowLayoutManager, WindowStateObserver implementation:

Expand Down Expand Up @@ -894,10 +892,11 @@ void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) {
DCHECK(!is_dragged_window_docked_);
}
if (window == last_active_window_)
last_active_window_ = nullptr;
last_active_window_ = NULL;
RecordUmaAction(DOCKED_ACTION_CLOSE, event_source_);
}


////////////////////////////////////////////////////////////////////////////////
// DockedWindowLayoutManager, aura::client::ActivationChangeObserver
// implementation:
Expand All @@ -909,7 +908,7 @@ void DockedWindowLayoutManager::OnWindowActivated(
if (gained_active && IsPopupOrTransient(gained_active))
return;
// Ignore if the window that is not managed by this was activated.
aura::Window* ancestor = nullptr;
aura::Window* ancestor = NULL;
for (aura::Window* parent = gained_active;
parent; parent = parent->parent()) {
if (parent->parent() == dock_container_) {
Expand Down Expand Up @@ -1076,7 +1075,7 @@ void DockedWindowLayoutManager::Relayout() {
base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true);

gfx::Rect dock_bounds = dock_container_->GetBoundsInScreen();
aura::Window* active_window = nullptr;
aura::Window* active_window = NULL;
std::vector<WindowWithHeight> visible_windows;
for (size_t i = 0; i < dock_container_->children().size(); ++i) {
aura::Window* window(dock_container_->children()[i]);
Expand Down Expand Up @@ -1207,8 +1206,9 @@ void DockedWindowLayoutManager::FanOutChildren(
// Sort windows by their center positions and fan out overlapping
// windows.
std::sort(visible_windows->begin(), visible_windows->end(),
CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : nullptr,
dock_container_, delta));
CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : NULL,
dock_container_,
delta));
for (std::vector<WindowWithHeight>::iterator iter = visible_windows->begin();
iter != visible_windows->end(); ++iter) {
aura::Window* window = iter->window();
Expand Down Expand Up @@ -1292,14 +1292,11 @@ void DockedWindowLayoutManager::UpdateDockBounds(
gfx::Rect background_bounds(docked_bounds_);
if (shelf_observer_)
background_bounds.Subtract(shelf_observer_->shelf_bounds_in_screen());
if (docked_width_ > 0) {
if (!background_widget_)
background_widget_.reset(new DockedBackgroundWidget(dock_container_));
background_widget_->SetBackgroundBounds(background_bounds, alignment_);
background_widget_->SetBackgroundBounds(background_bounds, alignment_);
if (docked_width_ > 0)
background_widget_->Show();
} else if (background_widget_) {
else
background_widget_->Hide();
}
}

void DockedWindowLayoutManager::UpdateStacking(aura::Window* active_window) {
Expand Down Expand Up @@ -1335,7 +1332,7 @@ void DockedWindowLayoutManager::UpdateStacking(aura::Window* active_window) {
}
int active_center_y = active_window->bounds().CenterPoint().y();

aura::Window* previous_window = nullptr;
aura::Window* previous_window = NULL;
for (std::map<int, aura::Window*>::const_iterator it =
window_ordering.begin();
it != window_ordering.end() && it->first < active_center_y; ++it) {
Expand Down
7 changes: 7 additions & 0 deletions ash/wm/dock/docked_window_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>

#include "ash/ash_export.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
#include "ash/shell_observer.h"
#include "ash/snap_to_pixel_layout_manager.h"
#include "ash/wm/dock/dock_types.h"
Expand Down Expand Up @@ -40,6 +41,7 @@ class DockedBackgroundWidget;
class DockedWindowLayoutManagerObserver;
class DockedWindowResizerTest;
class Shelf;
class ShelfLayoutManager;
class WorkspaceController;

struct WindowWithHeight {
Expand Down Expand Up @@ -70,6 +72,7 @@ class ASH_EXPORT DockedWindowLayoutManager
public aura::WindowObserver,
public aura::client::ActivationChangeObserver,
public keyboard::KeyboardControllerObserver,
public ShelfLayoutManagerObserver,
public wm::WindowStateObserver {
public:
// Maximum width of the docked windows area.
Expand Down Expand Up @@ -160,6 +163,10 @@ class ASH_EXPORT DockedWindowLayoutManager
aura::Window* root_window) override;
void OnShelfAlignmentChanged(aura::Window* root_window) override;

// ShelfLayoutManagerObserver:
void OnBackgroundUpdated(ShelfBackgroundType background_type,
BackgroundAnimatorChangeType change_type) override;

// wm::WindowStateObserver:
void OnPreWindowStateTypeChange(wm::WindowState* window_state,
wm::WindowStateType old_type) override;
Expand Down

0 comments on commit bc758d4

Please sign in to comment.