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

Side by Side Diff: ash/root_window_controller.cc

Issue 93873013: Make sure the dragged window is smaller than work area in the target display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/root_window_controller.h" 5 #include "ash/root_window_controller.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_constants.h" 10 #include "ash/ash_constants.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "ash/wm/toplevel_window_event_handler.h" 44 #include "ash/wm/toplevel_window_event_handler.h"
45 #include "ash/wm/window_properties.h" 45 #include "ash/wm/window_properties.h"
46 #include "ash/wm/window_state.h" 46 #include "ash/wm/window_state.h"
47 #include "ash/wm/window_util.h" 47 #include "ash/wm/window_util.h"
48 #include "ash/wm/workspace_controller.h" 48 #include "ash/wm/workspace_controller.h"
49 #include "base/command_line.h" 49 #include "base/command_line.h"
50 #include "base/time/time.h" 50 #include "base/time/time.h"
51 #include "ui/aura/client/aura_constants.h" 51 #include "ui/aura/client/aura_constants.h"
52 #include "ui/aura/client/drag_drop_client.h" 52 #include "ui/aura/client/drag_drop_client.h"
53 #include "ui/aura/client/tooltip_client.h" 53 #include "ui/aura/client/tooltip_client.h"
54 #include "ui/aura/client/window_types.h"
54 #include "ui/aura/root_window.h" 55 #include "ui/aura/root_window.h"
55 #include "ui/aura/window.h" 56 #include "ui/aura/window.h"
56 #include "ui/aura/window_delegate.h" 57 #include "ui/aura/window_delegate.h"
57 #include "ui/aura/window_observer.h" 58 #include "ui/aura/window_observer.h"
58 #include "ui/aura/window_tracker.h" 59 #include "ui/aura/window_tracker.h"
59 #include "ui/base/hit_test.h" 60 #include "ui/base/hit_test.h"
60 #include "ui/base/models/menu_model.h" 61 #include "ui/base/models/menu_model.h"
61 #include "ui/gfx/display.h" 62 #include "ui/gfx/display.h"
62 #include "ui/gfx/screen.h" 63 #include "ui/gfx/screen.h"
63 #include "ui/keyboard/keyboard_controller.h" 64 #include "ui/keyboard/keyboard_controller.h"
(...skipping 26 matching lines...) Expand all
90 aura::Window* container = new aura::Window(NULL); 91 aura::Window* container = new aura::Window(NULL);
91 container->set_id(window_id); 92 container->set_id(window_id);
92 container->SetName(name); 93 container->SetName(name);
93 container->Init(ui::LAYER_NOT_DRAWN); 94 container->Init(ui::LAYER_NOT_DRAWN);
94 parent->AddChild(container); 95 parent->AddChild(container);
95 if (window_id != internal::kShellWindowId_UnparentedControlContainer) 96 if (window_id != internal::kShellWindowId_UnparentedControlContainer)
96 container->Show(); 97 container->Show();
97 return container; 98 return container;
98 } 99 }
99 100
101 float ToRelativeValue(int value, int src, int dst) {
102 return static_cast<float>(value) / static_cast<float>(src) * dst;
103 }
104
105 void AdjustBoundsRelativeToSize(const gfx::Size& src_size,
varkha 2013/12/12 16:20:46 nit: Maybe ShiftOriginRelativeToParentSize or Move
oshima 2013/12/12 19:07:14 Changed to MoveOriginRelativeToSize, as there is n
106 const gfx::Size& dst_size,
107 gfx::Rect* bounds_in_out) {
108 gfx::Point origin = bounds_in_out->origin();
109 bounds_in_out->set_origin(gfx::Point(
110 ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
111 ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
112 }
113
100 // Reparents |window| to |new_parent|. 114 // Reparents |window| to |new_parent|.
101 void ReparentWindow(aura::Window* window, aura::Window* new_parent) { 115 void ReparentWindow(aura::Window* window, aura::Window* new_parent) {
116 const gfx::Size src_size = window->parent()->bounds().size();
117 const gfx::Size dst_size = new_parent->bounds().size();
102 // Update the restore bounds to make it relative to the display. 118 // Update the restore bounds to make it relative to the display.
103 wm::WindowState* state = wm::GetWindowState(window); 119 wm::WindowState* state = wm::GetWindowState(window);
104 gfx::Rect restore_bounds; 120 gfx::Rect restore_bounds;
105 bool has_restore_bounds = state->HasRestoreBounds(); 121 bool has_restore_bounds = state->HasRestoreBounds();
106 if (has_restore_bounds) 122
123 // TODO(oshima): snapped state should be handled by the layout manager.
124 bool update_bounds = state->IsNormalShowState() || state->IsMinimized();
125 gfx::Rect local_bounds;
126 if (update_bounds) {
127 local_bounds = state->window()->bounds();
128 AdjustBoundsRelativeToSize(src_size, dst_size, &local_bounds);
129 }
130
131 if (has_restore_bounds) {
107 restore_bounds = state->GetRestoreBoundsInParent(); 132 restore_bounds = state->GetRestoreBoundsInParent();
133 AdjustBoundsRelativeToSize(src_size, dst_size, &restore_bounds);
134 }
135
108 new_parent->AddChild(window); 136 new_parent->AddChild(window);
137
138 if (update_bounds)
139 window->SetBounds(local_bounds);
140
109 if (has_restore_bounds) 141 if (has_restore_bounds)
110 state->SetRestoreBoundsInParent(restore_bounds); 142 state->SetRestoreBoundsInParent(restore_bounds);
111 } 143 }
112 144
113 // Reparents the appropriate set of windows from |src| to |dst|. 145 // Reparents the appropriate set of windows from |src| to |dst|.
114 void ReparentAllWindows(aura::Window* src, aura::Window* dst) { 146 void ReparentAllWindows(aura::Window* src, aura::Window* dst) {
115 // Set of windows to move. 147 // Set of windows to move.
116 const int kContainerIdsToMove[] = { 148 const int kContainerIdsToMove[] = {
117 internal::kShellWindowId_DefaultContainer, 149 internal::kShellWindowId_DefaultContainer,
118 internal::kShellWindowId_DockedContainer, 150 internal::kShellWindowId_DockedContainer,
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 DisableTouchHudProjection(); 961 DisableTouchHudProjection();
930 } 962 }
931 963
932 RootWindowController* GetRootWindowController( 964 RootWindowController* GetRootWindowController(
933 const aura::Window* root_window) { 965 const aura::Window* root_window) {
934 return root_window ? GetRootWindowSettings(root_window)->controller : NULL; 966 return root_window ? GetRootWindowSettings(root_window)->controller : NULL;
935 } 967 }
936 968
937 } // namespace internal 969 } // namespace internal
938 } // namespace ash 970 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/root_window_controller_unittest.cc » ('j') | ash/root_window_controller_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698