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

Side by Side Diff: ash/display/display_controller.cc

Issue 14188054: Restore focus/activation after the root window has been completely deleted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months 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
« no previous file with comments | « ash/display/display_controller.h ('k') | ash/root_window_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/display/display_controller.h" 5 #include "ash/display/display_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <map> 9 #include <map>
10 10
11 #include "ash/ash_root_window_transformer.h" 11 #include "ash/ash_root_window_transformer.h"
12 #include "ash/ash_switches.h" 12 #include "ash/ash_switches.h"
13 #include "ash/display/display_manager.h" 13 #include "ash/display/display_manager.h"
14 #include "ash/display/display_pref_util.h" 14 #include "ash/display/display_pref_util.h"
15 #include "ash/host/root_window_host_factory.h" 15 #include "ash/host/root_window_host_factory.h"
16 #include "ash/root_window_controller.h" 16 #include "ash/root_window_controller.h"
17 #include "ash/screen_ash.h" 17 #include "ash/screen_ash.h"
18 #include "ash/shell.h" 18 #include "ash/shell.h"
19 #include "ash/wm/coordinate_conversion.h" 19 #include "ash/wm/coordinate_conversion.h"
20 #include "ash/wm/property_util.h" 20 #include "ash/wm/property_util.h"
21 #include "ash/wm/window_util.h" 21 #include "ash/wm/window_util.h"
22 #include "base/command_line.h" 22 #include "base/command_line.h"
23 #include "base/json/json_value_converter.h" 23 #include "base/json/json_value_converter.h"
24 #include "base/stringprintf.h" 24 #include "base/stringprintf.h"
25 #include "base/strings/string_number_conversions.h" 25 #include "base/strings/string_number_conversions.h"
26 #include "base/strings/string_piece.h" 26 #include "base/strings/string_piece.h"
27 #include "base/values.h" 27 #include "base/values.h"
28 #include "third_party/skia/include/utils/SkMatrix44.h" 28 #include "third_party/skia/include/utils/SkMatrix44.h"
29 #include "ui/aura/client/activation_client.h"
30 #include "ui/aura/client/capture_client.h"
29 #include "ui/aura/client/cursor_client.h" 31 #include "ui/aura/client/cursor_client.h"
32 #include "ui/aura/client/focus_client.h"
30 #include "ui/aura/client/screen_position_client.h" 33 #include "ui/aura/client/screen_position_client.h"
31 #include "ui/aura/env.h" 34 #include "ui/aura/env.h"
32 #include "ui/aura/root_window.h" 35 #include "ui/aura/root_window.h"
33 #include "ui/aura/window.h" 36 #include "ui/aura/window.h"
34 #include "ui/aura/window_property.h" 37 #include "ui/aura/window_property.h"
38 #include "ui/aura/window_tracker.h"
35 #include "ui/compositor/compositor.h" 39 #include "ui/compositor/compositor.h"
36 #include "ui/compositor/dip_util.h" 40 #include "ui/compositor/dip_util.h"
37 #include "ui/gfx/display.h" 41 #include "ui/gfx/display.h"
38 #include "ui/gfx/screen.h" 42 #include "ui/gfx/screen.h"
39 43
40 #if defined(OS_CHROMEOS) 44 #if defined(OS_CHROMEOS)
41 #include "ash/display/output_configurator_animation.h" 45 #include "ash/display/output_configurator_animation.h"
42 #include "base/chromeos/chromeos_version.h" 46 #include "base/chromeos/chromeos_version.h"
43 #include "base/time.h" 47 #include "base/time.h"
44 #include "chromeos/display/output_configurator.h" 48 #include "chromeos/display/output_configurator.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 ui::SetIntProperty(xwindow, 224 ui::SetIntProperty(xwindow,
221 kScaleFactorProp, 225 kScaleFactorProp,
222 kCARDINAL, 226 kCARDINAL,
223 100 * display.device_scale_factor()); 227 100 * display.device_scale_factor());
224 #endif 228 #endif
225 RotateRootWindow(root, display, info); 229 RotateRootWindow(root, display, info);
226 } 230 }
227 231
228 } // namespace 232 } // namespace
229 233
234 namespace internal {
235
236 // A utility class to store/restore focused/active window
237 // when the display configuration has changed.
238 class FocusActivationStore {
239 public:
240 FocusActivationStore()
241 : activation_client_(NULL),
242 capture_client_(NULL),
243 focus_client_(NULL),
244 focused_(NULL),
245 active_(NULL) {
246 }
247
248 void Store() {
249 if (!activation_client_) {
250 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
251 activation_client_ = aura::client::GetActivationClient(root);
252 capture_client_ = aura::client::GetCaptureClient(root);
253 focus_client_ = aura::client::GetFocusClient(root);
254 }
255 focused_ = focus_client_->GetFocusedWindow();
256 if (focused_)
257 tracker_.Add(focused_);
258 active_ = activation_client_->GetActiveWindow();
259 if (active_ && focused_ != active_)
260 tracker_.Add(active_);
261
262 // Deactivate the window to close menu / bubble windows.
263 activation_client_->DeactivateWindow(active_);
264 // Release capture if any.
265 capture_client_->SetCapture(NULL);
266 // Clear the focused window if any. This is necessary because a
267 // window may be deleted when losing focus (fullscreen flash for
268 // example). If the focused window is still alive after move, it'll
269 // be re-focused below.
270 focus_client_->FocusWindow(NULL);
271 }
272
273 void Restore() {
274 // Restore focused or active window if it's still alive.
275 if (focused_ && tracker_.Contains(focused_)) {
276 focus_client_->FocusWindow(focused_);
277 } else if (active_ && tracker_.Contains(active_)) {
278 activation_client_->ActivateWindow(active_);
279 }
280 if (focused_)
281 tracker_.Remove(focused_);
282 if (active_)
283 tracker_.Remove(active_);
284 focused_ = NULL;
285 active_ = NULL;
286 }
287
288 private:
289 aura::client::ActivationClient* activation_client_;
290 aura::client::CaptureClient* capture_client_;
291 aura::client::FocusClient* focus_client_;
292 aura::WindowTracker tracker_;
293 aura::Window* focused_;
294 aura::Window* active_;
295
296 DISALLOW_COPY_AND_ASSIGN(FocusActivationStore);
297 };
298
299 } // namespace internal
300
230 //////////////////////////////////////////////////////////////////////////////// 301 ////////////////////////////////////////////////////////////////////////////////
231 // DisplayLayout 302 // DisplayLayout
232 303
233 // static 304 // static
234 DisplayLayout DisplayLayout::FromInts(int position, int offsets) { 305 DisplayLayout DisplayLayout::FromInts(int position, int offsets) {
235 return DisplayLayout(static_cast<Position>(position), offsets); 306 return DisplayLayout(static_cast<Position>(position), offsets);
236 } 307 }
237 308
238 DisplayLayout::DisplayLayout() 309 DisplayLayout::DisplayLayout()
239 : position(RIGHT), 310 : position(RIGHT),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 405
335 bool DisplayController::DisplayChangeLimiter::IsThrottled() const { 406 bool DisplayController::DisplayChangeLimiter::IsThrottled() const {
336 return base::Time::Now() < throttle_timeout_; 407 return base::Time::Now() < throttle_timeout_;
337 } 408 }
338 409
339 //////////////////////////////////////////////////////////////////////////////// 410 ////////////////////////////////////////////////////////////////////////////////
340 // DisplayController 411 // DisplayController
341 412
342 DisplayController::DisplayController() 413 DisplayController::DisplayController()
343 : primary_root_window_for_replace_(NULL), 414 : primary_root_window_for_replace_(NULL),
344 in_bootstrap_(true) { 415 in_bootstrap_(true),
416 focus_activation_store_(new internal::FocusActivationStore()) {
345 CommandLine* command_line = CommandLine::ForCurrentProcess(); 417 CommandLine* command_line = CommandLine::ForCurrentProcess();
346 #if defined(OS_CHROMEOS) 418 #if defined(OS_CHROMEOS)
347 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) && 419 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) &&
348 base::chromeos::IsRunningOnChromeOS()) 420 base::chromeos::IsRunningOnChromeOS())
349 limiter_.reset(new DisplayChangeLimiter); 421 limiter_.reset(new DisplayChangeLimiter);
350 #endif 422 #endif
351 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { 423 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) {
352 std::string value = command_line->GetSwitchValueASCII( 424 std::string value = command_line->GetSwitchValueASCII(
353 switches::kAshSecondaryDisplayLayout); 425 switches::kAshSecondaryDisplayLayout);
354 char layout; 426 char layout;
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); 1045 gfx::Insets insets = secondary_display->GetWorkAreaInsets();
974 secondary_display->set_bounds( 1046 secondary_display->set_bounds(
975 gfx::Rect(new_secondary_origin, secondary_bounds.size())); 1047 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
976 secondary_display->UpdateWorkAreaFromInsets(insets); 1048 secondary_display->UpdateWorkAreaFromInsets(insets);
977 } 1049 }
978 1050
979 void DisplayController::NotifyDisplayConfigurationChanging() { 1051 void DisplayController::NotifyDisplayConfigurationChanging() {
980 if (in_bootstrap()) 1052 if (in_bootstrap())
981 return; 1053 return;
982 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); 1054 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging());
1055 focus_activation_store_->Store();
983 } 1056 }
984 1057
985 void DisplayController::NotifyDisplayConfigurationChanged() { 1058 void DisplayController::NotifyDisplayConfigurationChanged() {
986 if (in_bootstrap()) 1059 if (in_bootstrap())
987 return; 1060 return;
1061 focus_activation_store_->Restore();
988 1062
989 internal::DisplayManager* display_manager = GetDisplayManager(); 1063 internal::DisplayManager* display_manager = GetDisplayManager();
990 if (display_manager->num_connected_displays() > 1) { 1064 if (display_manager->num_connected_displays() > 1) {
991 DisplayIdPair pair = GetCurrentDisplayIdPair(); 1065 DisplayIdPair pair = GetCurrentDisplayIdPair();
992 if (paired_layouts_.find(pair) == paired_layouts_.end()) 1066 if (paired_layouts_.find(pair) == paired_layouts_.end())
993 paired_layouts_[pair] = default_display_layout_; 1067 paired_layouts_[pair] = default_display_layout_;
994 paired_layouts_[pair].mirrored = display_manager->IsMirrored(); 1068 paired_layouts_[pair].mirrored = display_manager->IsMirrored();
995 if (Shell::GetScreen()->GetNumDisplays() > 1 ) { 1069 if (Shell::GetScreen()->GetNumDisplays() > 1 ) {
996 int64 primary_id = paired_layouts_[pair].primary_id; 1070 int64 primary_id = paired_layouts_[pair].primary_id;
997 SetPrimaryDisplayId( 1071 SetPrimaryDisplayId(
(...skipping 20 matching lines...) Expand all
1018 } 1092 }
1019 1093
1020 void DisplayController::OnFadeOutForSwapDisplayFinished() { 1094 void DisplayController::OnFadeOutForSwapDisplayFinished() {
1021 #if defined(OS_CHROMEOS) 1095 #if defined(OS_CHROMEOS)
1022 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); 1096 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay());
1023 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); 1097 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation();
1024 #endif 1098 #endif
1025 } 1099 }
1026 1100
1027 } // namespace ash 1101 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_controller.h ('k') | ash/root_window_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698