OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 "window_manager/layout_manager.h" | 5 #include "window_manager/layout_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <cstdio> | 9 #include <cstdio> |
10 #include <tr1/memory> | 10 #include <tr1/memory> |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 mode_(MODE_ACTIVE), | 75 mode_(MODE_ACTIVE), |
76 x_(0), | 76 x_(0), |
77 y_(0), | 77 y_(0), |
78 width_(wm_->width()), | 78 width_(wm_->width()), |
79 height_(wm_->height()), | 79 height_(wm_->height()), |
80 panel_manager_left_width_(0), | 80 panel_manager_left_width_(0), |
81 panel_manager_right_width_(0), | 81 panel_manager_right_width_(0), |
82 current_toplevel_(NULL), | 82 current_toplevel_(NULL), |
83 current_snapshot_(NULL), | 83 current_snapshot_(NULL), |
84 fullscreen_toplevel_(NULL), | 84 fullscreen_toplevel_(NULL), |
85 overview_panning_offset_(0), | 85 overview_panning_offset_(INT_MAX), |
86 overview_background_offset_(0), | 86 overview_background_offset_(0), |
87 overview_width_of_snapshots_(0), | 87 overview_width_of_snapshots_(0), |
88 overview_background_event_coalescer_( | 88 overview_background_event_coalescer_( |
89 new MotionEventCoalescer( | 89 new MotionEventCoalescer( |
90 wm_->event_loop(), | 90 wm_->event_loop(), |
91 NewPermanentCallback( | 91 NewPermanentCallback( |
92 this, &LayoutManager::UpdateOverviewPanningForMotion), | 92 this, &LayoutManager::UpdateOverviewPanningForMotion), |
93 kOverviewDragUpdateMs)), | 93 kOverviewDragUpdateMs)), |
94 overview_drag_last_x_(-1), | 94 overview_drag_last_x_(-1), |
95 saw_map_request_(false), | 95 saw_map_request_(false), |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 | 842 |
843 if (background_.get()) | 843 if (background_.get()) |
844 background_->MoveX(overview_background_offset_, | 844 background_->MoveX(overview_background_offset_, |
845 animate ? kWindowAnimMs : 0); | 845 animate ? kWindowAnimMs : 0); |
846 | 846 |
847 if (wm_->client_window_debugging_enabled()) | 847 if (wm_->client_window_debugging_enabled()) |
848 wm_->UpdateClientWindowDebugging(); | 848 wm_->UpdateClientWindowDebugging(); |
849 } | 849 } |
850 | 850 |
851 void LayoutManager::SetMode(Mode mode) { | 851 void LayoutManager::SetMode(Mode mode) { |
852 // Just treat the active-cancelled state as regular active mode; we're | 852 // Just treat the active-cancelled state as regular active mode; |
853 // really just using it to pass an extra bit of information into this | 853 // we're really just using it to pass an extra bit of information |
854 // method so we can notify Chrome that overview mode was cancelled. | 854 // into this method so we can notify Chrome that overview mode was |
| 855 // cancelled. Cancelling actually happens on the Chrome side, since |
| 856 // it knows what tabs used to be selected. |
855 bool was_cancelled = false; | 857 bool was_cancelled = false; |
856 if (mode == MODE_ACTIVE_CANCELLED) { | 858 if (mode == MODE_ACTIVE_CANCELLED) { |
857 was_cancelled = true; | 859 was_cancelled = true; |
858 mode = MODE_ACTIVE; | 860 mode = MODE_ACTIVE; |
859 } | 861 } |
860 | 862 |
861 if (mode == mode_) | 863 if (mode == mode_) |
862 return; | 864 return; |
863 | 865 |
864 if (wm_->logged_in()) | 866 if (wm_->logged_in()) |
865 DisableKeyBindingsForMode(mode_); | 867 DisableKeyBindingsForMode(mode_); |
866 | 868 |
867 mode_ = mode; | 869 mode_ = mode; |
868 DLOG(INFO) << "Switching to " << GetModeName(mode_) << " mode"; | 870 DLOG(INFO) << "Switching to " << GetModeName(mode_) << " mode"; |
869 | 871 |
870 switch (mode_) { | 872 switch (mode_) { |
871 case MODE_ACTIVE: | 873 case MODE_ACTIVE: |
872 // Cancelling actually happens on the Chrome side, since it | |
873 // knows what tabs used to be selected. It knows to cancel | |
874 // because it's a different layout mode. | |
875 if (current_toplevel_) | 874 if (current_toplevel_) |
876 current_toplevel_->TakeFocus(wm_->GetCurrentTimeFromServer()); | 875 current_toplevel_->TakeFocus(wm_->GetCurrentTimeFromServer()); |
877 for (ToplevelWindows::iterator it = toplevels_.begin(); | 876 for (ToplevelWindows::iterator it = toplevels_.begin(); |
878 it != toplevels_.end(); ++it) { | 877 it != toplevels_.end(); ++it) { |
879 if (it->get() == current_toplevel_) { | 878 if (it->get() == current_toplevel_) { |
880 (*it)->SetState(ToplevelWindow::STATE_ACTIVE_MODE_IN_FADE); | 879 (*it)->SetState(ToplevelWindow::STATE_ACTIVE_MODE_IN_FADE); |
881 } else { | 880 } else { |
882 (*it)->SetState(ToplevelWindow::STATE_ACTIVE_MODE_OFFSCREEN); | 881 (*it)->SetState(ToplevelWindow::STATE_ACTIVE_MODE_OFFSCREEN); |
883 } | 882 } |
884 } | 883 } |
885 for (SnapshotWindows::iterator it = snapshots_.begin(); | 884 for (SnapshotWindows::iterator it = snapshots_.begin(); |
886 it != snapshots_.end(); ++it) { | 885 it != snapshots_.end(); ++it) { |
887 (*it)->SetState(SnapshotWindow::STATE_ACTIVE_MODE_INVISIBLE); | 886 (*it)->SetState(SnapshotWindow::STATE_ACTIVE_MODE_INVISIBLE); |
888 } | 887 } |
889 for (Separators::iterator it = separators_.begin(); | 888 for (Separators::iterator it = separators_.begin(); |
890 it != separators_.end(); ++it) { | 889 it != separators_.end(); ++it) { |
891 (*it)->SetState(Separator::STATE_ACTIVE_MODE_INVISIBLE); | 890 (*it)->SetState(Separator::STATE_ACTIVE_MODE_INVISIBLE); |
892 } | 891 } |
893 break; | 892 break; |
894 case MODE_OVERVIEW: { | 893 case MODE_OVERVIEW: { |
895 UpdateCurrentSnapshot(); | 894 UpdateCurrentSnapshot(); |
| 895 |
896 if (current_toplevel_ && | 896 if (current_toplevel_ && |
897 current_toplevel_->IsWindowOrTransientFocused()) { | 897 current_toplevel_->IsWindowOrTransientFocused()) { |
898 // We need to give the input focus away here; otherwise the | 898 // We need to give the input focus away here; otherwise the |
899 // previously-focused window would continue to get keyboard events | 899 // previously-focused window would continue to get keyboard events |
900 // in overview mode. Let the WindowManager decide what to do with it. | 900 // in overview mode. Let the WindowManager decide what to do with it. |
901 wm_->TakeFocus(wm_->GetCurrentTimeFromServer()); | 901 wm_->TakeFocus(wm_->GetCurrentTimeFromServer()); |
902 } | 902 } |
903 | 903 |
904 for (ToplevelWindows::iterator it = toplevels_.begin(); | 904 for (ToplevelWindows::iterator it = toplevels_.begin(); |
905 it != toplevels_.end(); ++it) { | 905 it != toplevels_.end(); ++it) { |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 overview_width_of_snapshots_ = running_width - kOverviewSelectedPadding; | 1252 overview_width_of_snapshots_ = running_width - kOverviewSelectedPadding; |
1253 } | 1253 } |
1254 | 1254 |
1255 if (enforce_bounds) { | 1255 if (enforce_bounds) { |
1256 const float kMargin = width_ * kSideMarginRatio; | 1256 const float kMargin = width_ * kSideMarginRatio; |
1257 int min_x = kMargin; | 1257 int min_x = kMargin; |
1258 int max_x = width_ - overview_width_of_snapshots_ - kMargin; | 1258 int max_x = width_ - overview_width_of_snapshots_ - kMargin; |
1259 if (max_x < min_x) | 1259 if (max_x < min_x) |
1260 std::swap(max_x, min_x); | 1260 std::swap(max_x, min_x); |
1261 | 1261 |
| 1262 // If we haven't set the panning offset before, center the current |
| 1263 // snapshot. |
| 1264 if (overview_panning_offset_ == INT_MAX) |
| 1265 CenterCurrentSnapshot(-1, -1); |
| 1266 |
1262 // There's two modes here: one where the snapshots are too wide | 1267 // There's two modes here: one where the snapshots are too wide |
1263 // to fit, and one where they aren't. Just so happens that we | 1268 // to fit, and one where they aren't. Just so happens that we |
1264 // want to do similar things in both cases. | 1269 // want to do similar things in both cases. |
1265 if (overview_panning_offset_ < min_x) { | 1270 if (overview_panning_offset_ < min_x) { |
1266 overview_panning_offset_ = min_x; | 1271 overview_panning_offset_ = min_x; |
1267 } else { | 1272 } else { |
1268 if (snapshots_.size() > 0) { | 1273 if (snapshots_.size() > 0) { |
1269 if (overview_panning_offset_ > max_x) | 1274 if (overview_panning_offset_ > max_x) |
1270 overview_panning_offset_ = max_x; | 1275 overview_panning_offset_ = max_x; |
1271 } else { | 1276 } else { |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1782 PLOG(ERROR) << "Unable to open file " | 1787 PLOG(ERROR) << "Unable to open file " |
1783 << FLAGS_initial_chrome_window_mapped_file; | 1788 << FLAGS_initial_chrome_window_mapped_file; |
1784 } else { | 1789 } else { |
1785 fprintf(file, "%lu", win->xid()); | 1790 fprintf(file, "%lu", win->xid()); |
1786 fclose(file); | 1791 fclose(file); |
1787 } | 1792 } |
1788 } | 1793 } |
1789 } | 1794 } |
1790 | 1795 |
1791 } // namespace window_manager | 1796 } // namespace window_manager |
OLD | NEW |