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

Unified Diff: ui/views/mus/desktop_window_tree_host_mus.cc

Issue 2490273002: Couple of fixes for DesktopWindowTreeHostMus. (Closed)
Patch Set: cleanup Created 4 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
« no previous file with comments | « ui/views/bubble/bubble_frame_view.cc ('k') | ui/views/widget/desktop_aura/desktop_native_widget_aura.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/mus/desktop_window_tree_host_mus.cc
diff --git a/ui/views/mus/desktop_window_tree_host_mus.cc b/ui/views/mus/desktop_window_tree_host_mus.cc
index d5464b6a1561081aa1d368c5041d8e612e43043c..b8387f0dbc2dec32563811218732d933a6e8efc0 100644
--- a/ui/views/mus/desktop_window_tree_host_mus.cc
+++ b/ui/views/mus/desktop_window_tree_host_mus.cc
@@ -46,7 +46,11 @@ bool DesktopWindowTreeHostMus::IsDocked() const {
}
void DesktopWindowTreeHostMus::Init(aura::Window* content_window,
- const Widget::InitParams& params) {}
+ const Widget::InitParams& params) {
+ // TODO: handle device scale, http://crbug.com/663524.
+ if (!params.bounds.IsEmpty())
+ SetBounds(params.bounds);
+}
void DesktopWindowTreeHostMus::OnNativeWidgetCreated(
const Widget::InitParams& params) {
@@ -110,8 +114,8 @@ void DesktopWindowTreeHostMus::ShowWindowWithState(ui::WindowShowState state) {
window()->Show();
if (compositor())
compositor()->SetVisible(true);
- // TODO: likely needs code to activate, but after content_window_ is shown.
- // See NativeWidgetAura::ShowWithWindowState().
+
+ native_widget_delegate_->AsWidget()->SetInitialFocus(state);
msw 2016/11/10 18:27:45 q: Should this check if native_widget_delgate_->Ca
sky 2016/11/10 20:18:11 I'm not exactly sure. That doesn't exist in the de
}
void DesktopWindowTreeHostMus::ShowMaximizedWithBounds(
@@ -152,7 +156,33 @@ void DesktopWindowTreeHostMus::StackAtTop() {
}
void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) {
- NOTIMPLEMENTED();
+ gfx::Rect bounds_to_center_in = GetWorkAreaBoundsInScreen();
+
+ // If there is a transient parent and it fits |size|, then center over it.
+ aura::Window* content_window = desktop_native_widget_aura_->content_window();
+ if (wm::GetTransientParent(content_window)) {
+ gfx::Rect transient_parent_bounds =
+ wm::GetTransientParent(content_window)->GetBoundsInScreen();
+ if (transient_parent_bounds.height() >= size.height() &&
+ transient_parent_bounds.width() >= size.width()) {
+ bounds_to_center_in = transient_parent_bounds;
+ }
+ }
+
+ gfx::Rect resulting_bounds(
msw 2016/11/10 18:27:45 Use gfx::Rect::ClampToCenteredSize, then skip Adju
sky 2016/11/10 20:18:11 Good call! Done.
+ bounds_to_center_in.x() +
+ (bounds_to_center_in.width() - size.width()) / 2,
+ bounds_to_center_in.y() +
+ (bounds_to_center_in.height() - size.height()) / 2,
+ size.width(), size.height());
+
+ // Don't size the window bigger than the parent, otherwise the user may not be
+ // able to close or move it.
+ resulting_bounds.AdjustToFit(bounds_to_center_in);
+
+ // TODO: handle device scale, http://crbug.com/663524. SetBounds() expects
+ // pixels.
+ SetBounds(resulting_bounds);
}
void DesktopWindowTreeHostMus::GetWindowPlacement(
@@ -261,7 +291,10 @@ bool DesktopWindowTreeHostMus::IsMinimized() const {
}
bool DesktopWindowTreeHostMus::HasCapture() const {
- return const_cast<aura::Window*>(window())->HasCapture();
+ // Capture state is held by DesktopNativeWidgetAura::content_window_.
+ // DesktopNativeWidgetAura::HasCapture() calls content_window_->HasCapture(),
+ // and this. That means this function can always return true.
+ return true;
}
void DesktopWindowTreeHostMus::SetAlwaysOnTop(bool always_on_top) {
« no previous file with comments | « ui/views/bubble/bubble_frame_view.cc ('k') | ui/views/widget/desktop_aura/desktop_native_widget_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698