Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Fixes two bugs in causing demo_launcher to crash
Browse files Browse the repository at this point in the history
. MoveToFront/Back triggered a DCHECK. Made them early out if view
  already in position.
. Called WindowManagerApp::InitFocus so that we don't crash when
  WM::SetFocus is called.

BUG=none
TEST=none
[email protected]

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

Cr-Commit-Position: refs/heads/master@{#297559}
  • Loading branch information
sky authored and Commit bot committed Oct 1, 2014
1 parent eb15bc7 commit d102d04
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions mojo/examples/window_manager/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ shared_library("window_manager") {
"//ui/gl",
"//ui/resources",
"//ui/views",
"//ui/wm",
]
}

Expand Down
1 change: 1 addition & 0 deletions mojo/examples/window_manager/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ include_rules = [
"+ui/events",
"+ui/gfx",
"+ui/views",
"+ui/wm/core",
]
62 changes: 62 additions & 0 deletions mojo/examples/window_manager/window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/wm/core/focus_rules.h"

#if defined CreateWindow
#undef CreateWindow
Expand All @@ -45,6 +46,64 @@ const int kBorderInset = 25;
const int kControlPanelWidth = 200;
const int kTextfieldHeight = 25;

class WMFocusRules : public wm::FocusRules {
public:
WMFocusRules(mojo::WindowManagerApp* window_manager_app,
mojo::View* window_container)
: window_container_(window_container),
window_manager_app_(window_manager_app) {}
virtual ~WMFocusRules() {}

private:
// Overridden from wm::FocusRules:
virtual bool IsToplevelWindow(aura::Window* window) const override {
return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
window_container_;
}
virtual bool CanActivateWindow(aura::Window* window) const override {
return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
window_container_;
}
virtual bool CanFocusWindow(aura::Window* window) const override {
return true;
}
virtual aura::Window* GetToplevelWindow(aura::Window* window) const override {
mojo::View* view = mojo::WindowManagerApp::GetViewForWindow(window);
while (view->parent() != window_container_) {
view = view->parent();
// Unparented hierarchy, there is no "top level" window.
if (!view)
return NULL;
}

return window_manager_app_->GetWindowForViewId(view->id());
}
virtual aura::Window* GetActivatableWindow(
aura::Window* window) const override {
return GetToplevelWindow(window);
}
virtual aura::Window* GetFocusableWindow(
aura::Window* window) const override {
return window;
}
virtual aura::Window* GetNextActivatableWindow(
aura::Window* ignore) const override {
aura::Window* activatable = GetActivatableWindow(ignore);
const aura::Window::Windows& children = activatable->parent()->children();
for (aura::Window::Windows::const_reverse_iterator it = children.rbegin();
it != children.rend(); ++it) {
if (*it != ignore)
return *it;
}
return NULL;
}

mojo::View* window_container_;
mojo::WindowManagerApp* window_manager_app_;

DISALLOW_COPY_AND_ASSIGN(WMFocusRules);
};

} // namespace

class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
Expand Down Expand Up @@ -385,6 +444,9 @@ class WindowManager
root->AddObserver(root_layout_manager_.get());

window_manager_app_->host()->window()->AddPreTargetHandler(this);

window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(),
view));
}
virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {
DCHECK_EQ(view_manager_, view_manager);
Expand Down
1 change: 1 addition & 0 deletions mojo/mojo_examples.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@
'../ui/resources/ui_resources.gyp:ui_resources',
'../ui/resources/ui_resources.gyp:ui_test_pak',
'../ui/views/views.gyp:views',
'../ui/wm/wm.gyp:wm',
'mojo_base.gyp:mojo_application_chromium',
'mojo_base.gyp:mojo_cpp_bindings',
'mojo_base.gyp:mojo_utility',
Expand Down
4 changes: 4 additions & 0 deletions mojo/services/public/cpp/view_manager/lib/view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,14 @@ void View::RemoveChild(View* child) {
}

void View::MoveToFront() {
if (!parent_ || parent_->children_.back() == this)
return;
Reorder(parent_->children_.back(), ORDER_DIRECTION_ABOVE);
}

void View::MoveToBack() {
if (!parent_ || parent_->children_.front() == this)
return;
Reorder(parent_->children_.front(), ORDER_DIRECTION_BELOW);
}

Expand Down

0 comments on commit d102d04

Please sign in to comment.