| 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/panels/panel_dock.h" | 5 #include "window_manager/panels/panel_dock.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include <gflags/gflags.h> | 10 #include <gflags/gflags.h> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 bg_shadow_->MoveX(x_, kBackgroundAnimMs); | 117 bg_shadow_->MoveX(x_, kBackgroundAnimMs); |
| 118 bg_shadow_->SetOpacity(1, kBackgroundAnimMs); | 118 bg_shadow_->SetOpacity(1, kBackgroundAnimMs); |
| 119 panel_manager_->HandleDockVisibilityChange(this); | 119 panel_manager_->HandleDockVisibilityChange(this); |
| 120 } | 120 } |
| 121 | 121 |
| 122 panel->StackAtTopOfLayer( | 122 panel->StackAtTopOfLayer( |
| 123 source == PANEL_SOURCE_DRAGGED ? | 123 source == PANEL_SOURCE_DRAGGED ? |
| 124 StackingManager::LAYER_DRAGGED_PANEL : | 124 StackingManager::LAYER_DRAGGED_PANEL : |
| 125 StackingManager::LAYER_PACKED_PANEL_IN_DOCK); | 125 StackingManager::LAYER_PACKED_PANEL_IN_DOCK); |
| 126 | 126 |
| 127 int panel_x = (type_ == DOCK_TYPE_RIGHT) ? x_ + width_ : x_ + panel->width(); |
| 127 // Try to make the panel fit vertically within our dimensions. | 128 // Try to make the panel fit vertically within our dimensions. |
| 128 int panel_y = panel->titlebar_y(); | 129 int panel_y = panel->titlebar_y(); |
| 129 if (panel_y + panel->total_height() > y_ + height_) | 130 if (panel_y + panel->total_height() > y_ + height_) |
| 130 panel_y = y_ + height_ - panel->total_height(); | 131 panel_y = y_ + height_ - panel->total_height(); |
| 131 if (panel_y < y_) | 132 if (panel_y < y_) |
| 132 panel_y = y_; | 133 panel_y = y_; |
| 133 panel->Move(type_ == DOCK_TYPE_RIGHT ? x_ + width_ : x_ + panel->width(), | 134 panel->Move(Point(panel_x, panel_y), 0); |
| 134 panel_y, | |
| 135 0); | |
| 136 // TODO: Ideally, we would resize the panel here to match our width, but | 135 // TODO: Ideally, we would resize the panel here to match our width, but |
| 137 // that messes up the subsequent notification messages about the panel | 136 // that messes up the subsequent notification messages about the panel |
| 138 // being dragged -- some of them will be with regard to the panel's old | 137 // being dragged -- some of them will be with regard to the panel's old |
| 139 // dimensions and others will be with regard to the new dimensions. | 138 // dimensions and others will be with regard to the new dimensions. |
| 140 // Instead, we defer resizing the panel until the drag is complete. | 139 // Instead, we defer resizing the panel until the drag is complete. |
| 141 } | 140 } |
| 142 | 141 |
| 143 void PanelDock::RemovePanel(Panel* panel) { | 142 void PanelDock::RemovePanel(Panel* panel) { |
| 144 if (dragged_panel_ == panel) | 143 if (dragged_panel_ == panel) |
| 145 dragged_panel_ = NULL; | 144 dragged_panel_ = NULL; |
| 146 | 145 |
| 147 vector<Panel*>::iterator it = find(panels_.begin(), panels_.end(), panel); | 146 vector<Panel*>::iterator it = find(panels_.begin(), panels_.end(), panel); |
| 148 DCHECK(it != panels_.end()); | 147 DCHECK(it != panels_.end()); |
| 149 panels_.erase(it); | 148 panels_.erase(it); |
| 150 CHECK(static_cast<int>(panel_infos_.erase(panel)) == 1); | 149 CHECK(static_cast<int>(panel_infos_.erase(panel)) == 1); |
| 151 | 150 |
| 152 if (panels_.empty()) { | 151 if (panels_.empty()) { |
| 153 const int bg_x = type_ == DOCK_TYPE_LEFT ? x_ - width_ : x_ + width_; | 152 const int bg_x = type_ == DOCK_TYPE_LEFT ? x_ - width_ : x_ + width_; |
| 154 wm()->xconn()->ConfigureWindowOffscreen(bg_input_xid_); | 153 wm()->xconn()->ConfigureWindowOffscreen(bg_input_xid_); |
| 155 bg_actor_->MoveX(bg_x, kBackgroundAnimMs); | 154 bg_actor_->MoveX(bg_x, kBackgroundAnimMs); |
| 156 bg_shadow_->MoveX(bg_x, kBackgroundAnimMs); | 155 bg_shadow_->MoveX(bg_x, kBackgroundAnimMs); |
| 157 bg_shadow_->SetOpacity(0, kBackgroundAnimMs); | 156 bg_shadow_->SetOpacity(0, kBackgroundAnimMs); |
| 158 panel_manager_->HandleDockVisibilityChange(this); | 157 panel_manager_->HandleDockVisibilityChange(this); |
| 159 } else { | 158 } else { |
| 160 PackPanels(dragged_panel_); | 159 PackPanels(dragged_panel_); |
| 161 } | 160 } |
| 162 } | 161 } |
| 163 | 162 |
| 164 bool PanelDock::ShouldAddDraggedPanel(const Panel* panel, | 163 bool PanelDock::ShouldAddDraggedPanel(const Panel* panel, |
| 165 int drag_x, | 164 const Point& drag_pos) { |
| 166 int drag_y) { | |
| 167 return (type_ == DOCK_TYPE_RIGHT) ? | 165 return (type_ == DOCK_TYPE_RIGHT) ? |
| 168 drag_x >= x_ + width_ - kAttachThresholdPixels : | 166 drag_pos.x >= x_ + width_ - kAttachThresholdPixels : |
| 169 drag_x - panel->content_width() <= x_ + kAttachThresholdPixels; | 167 drag_pos.x - panel->content_width() <= x_ + kAttachThresholdPixels; |
| 170 } | 168 } |
| 171 | 169 |
| 172 void PanelDock::HandlePanelButtonPress(Panel* panel, | 170 void PanelDock::HandlePanelButtonPress(Panel* panel, |
| 173 int button, | 171 int button, |
| 174 XTime timestamp) { | 172 XTime timestamp) { |
| 175 FocusPanel(panel, timestamp); | 173 FocusPanel(panel, timestamp); |
| 176 } | 174 } |
| 177 | 175 |
| 178 void PanelDock::HandleSetPanelStateMessage(Panel* panel, bool expand) { | 176 void PanelDock::HandleSetPanelStateMessage(Panel* panel, bool expand) { |
| 179 LOG(WARNING) << "Ignoring request to " << (expand ? "expand" : "collapse") | 177 LOG(WARNING) << "Ignoring request to " << (expand ? "expand" : "collapse") |
| 180 << " docked panel " << panel->xid_str(); | 178 << " docked panel " << panel->xid_str(); |
| 181 } | 179 } |
| 182 | 180 |
| 183 bool PanelDock::HandleNotifyPanelDraggedMessage(Panel* panel, | 181 bool PanelDock::HandleNotifyPanelDraggedMessage(Panel* panel, |
| 184 int drag_x, | 182 const Point& drag_pos) { |
| 185 int drag_y) { | |
| 186 if (type_ == DOCK_TYPE_RIGHT) { | 183 if (type_ == DOCK_TYPE_RIGHT) { |
| 187 if (drag_x <= x_ + width_ - kDetachThresholdPixels) | 184 if (drag_pos.x <= x_ + width_ - kDetachThresholdPixels) |
| 188 return false; | 185 return false; |
| 189 } else { | 186 } else { |
| 190 if (drag_x - panel->content_width() >= x_ + kDetachThresholdPixels) | 187 if (drag_pos.x - panel->content_width() >= x_ + kDetachThresholdPixels) |
| 191 return false; | 188 return false; |
| 192 } | 189 } |
| 193 | 190 |
| 194 if (dragged_panel_ != panel) { | 191 if (dragged_panel_ != panel) { |
| 195 dragged_panel_ = panel; | 192 dragged_panel_ = panel; |
| 196 panel->StackAtTopOfLayer(StackingManager::LAYER_DRAGGED_PANEL); | 193 panel->StackAtTopOfLayer(StackingManager::LAYER_DRAGGED_PANEL); |
| 197 panel->SetShadowOpacity(1, kPanelShadowAnimMs); | 194 panel->SetShadowOpacity(1, kPanelShadowAnimMs); |
| 198 } | 195 } |
| 199 | 196 |
| 200 // Cap the drag position within the Y bounds of the dock. | 197 // Cap the drag position within the Y bounds of the dock. |
| 201 if (drag_y + panel->total_height() > y_ + height_) | 198 Point capped_pos = drag_pos; |
| 202 drag_y = y_ + height_ - panel->total_height(); | 199 if (capped_pos.y + panel->total_height() > y_ + height_) |
| 203 if (drag_y < y_) | 200 capped_pos.y = y_ + height_ - panel->total_height(); |
| 204 drag_y = y_; | 201 if (capped_pos.y < y_) |
| 202 capped_pos.y = y_; |
| 205 | 203 |
| 206 panel->MoveY(drag_y, 0); | 204 panel->MoveY(capped_pos.y, 0); |
| 207 ReorderPanel(panel); | 205 ReorderPanel(panel); |
| 208 return true; | 206 return true; |
| 209 } | 207 } |
| 210 | 208 |
| 211 void PanelDock::HandleNotifyPanelDragCompleteMessage(Panel* panel) { | 209 void PanelDock::HandleNotifyPanelDragCompleteMessage(Panel* panel) { |
| 212 if (dragged_panel_ != panel) | 210 if (dragged_panel_ != panel) |
| 213 return; | 211 return; |
| 214 // Move client windows. | 212 // Move client windows. |
| 215 panel->Move(panel->right(), panel->titlebar_y(), 0); | 213 panel->Move(Point(panel->right(), panel->titlebar_y()), 0); |
| 216 if (panel->width() != width_) { | 214 if (panel->width() != width_) { |
| 217 panel->ResizeContent( | 215 panel->ResizeContent( |
| 218 width_, panel->content_height(), | 216 Size(width_, panel->content_height()), |
| 219 type_ == DOCK_TYPE_RIGHT ? GRAVITY_NORTHEAST : GRAVITY_NORTHWEST, | 217 type_ == DOCK_TYPE_RIGHT ? GRAVITY_NORTHEAST : GRAVITY_NORTHWEST, |
| 220 true); | 218 true); |
| 221 } | 219 } |
| 222 panel->SetShadowOpacity(0, kPanelShadowAnimMs); | 220 panel->SetShadowOpacity(0, kPanelShadowAnimMs); |
| 223 panel->StackAtTopOfLayer(StackingManager::LAYER_PACKED_PANEL_IN_DOCK); | 221 panel->StackAtTopOfLayer(StackingManager::LAYER_PACKED_PANEL_IN_DOCK); |
| 224 dragged_panel_ = NULL; | 222 dragged_panel_ = NULL; |
| 225 PackPanels(NULL); | 223 PackPanels(NULL); |
| 226 } | 224 } |
| 227 | 225 |
| 228 void PanelDock::HandleFocusPanelMessage(Panel* panel, XTime timestamp) { | 226 void PanelDock::HandleFocusPanelMessage(Panel* panel, XTime timestamp) { |
| 229 DCHECK(panel); | 227 DCHECK(panel); |
| 230 FocusPanel(panel, timestamp); | 228 FocusPanel(panel, timestamp); |
| 231 } | 229 } |
| 232 | 230 |
| 233 void PanelDock::HandlePanelResizeRequest(Panel* panel, | 231 void PanelDock::HandlePanelResizeRequest(Panel* panel, |
| 234 int req_width, int req_height) { | 232 const Size& requested_size) { |
| 235 | 233 |
| 236 DCHECK(panel); | 234 DCHECK(panel); |
| 237 | 235 |
| 236 Size adjusted_size = requested_size; |
| 237 |
| 238 // We ignore requests to change the panel's width. | 238 // We ignore requests to change the panel's width. |
| 239 if (req_width != panel->content_width()) { | 239 if (requested_size.width != panel->content_width()) { |
| 240 LOG(WARNING) << "Ignoring width resize request for docked panel " | 240 LOG(WARNING) << "Ignoring width resize request for docked panel " |
| 241 << panel->xid_str() << " (orig was " << panel->content_width() | 241 << panel->xid_str() << " (orig was " << panel->content_size() |
| 242 << "x" << panel->content_height() << "), new is " << req_width | 242 << ", new is " << requested_size << ")"; |
| 243 << "x" << req_height << ")"; | 243 adjusted_size.width = panel->content_width(); |
| 244 req_width = panel->content_width(); | |
| 245 } | 244 } |
| 246 panel->ResizeContent(req_width, req_height, GRAVITY_NORTHWEST, true); | 245 panel->ResizeContent(adjusted_size, GRAVITY_NORTHWEST, true); |
| 247 PackPanels(dragged_panel_); | 246 PackPanels(dragged_panel_); |
| 248 } | 247 } |
| 249 | 248 |
| 250 void PanelDock::HandleScreenResize() { | 249 void PanelDock::HandleScreenResize() { |
| 251 height_ = wm()->height(); | 250 height_ = wm()->height(); |
| 252 if (type_ == DOCK_TYPE_RIGHT) | 251 if (type_ == DOCK_TYPE_RIGHT) |
| 253 x_ = wm()->width() - width_; | 252 x_ = wm()->width() - width_; |
| 254 | 253 |
| 255 bool hidden = panels_.empty(); | 254 bool hidden = panels_.empty(); |
| 256 | 255 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 void PanelDock::ResizeBackgroundActor(int width, int height) { | 354 void PanelDock::ResizeBackgroundActor(int width, int height) { |
| 356 DCHECK(bg_actor_.get()); | 355 DCHECK(bg_actor_.get()); |
| 357 DCHECK_GT(width, 0); | 356 DCHECK_GT(width, 0); |
| 358 DCHECK_GT(height, 0); | 357 DCHECK_GT(height, 0); |
| 359 bg_actor_->Scale(static_cast<float>(width_) / bg_actor_->GetWidth(), | 358 bg_actor_->Scale(static_cast<float>(width_) / bg_actor_->GetWidth(), |
| 360 static_cast<float>(height_) / bg_actor_->GetHeight(), | 359 static_cast<float>(height_) / bg_actor_->GetHeight(), |
| 361 0); // anim_ms | 360 0); // anim_ms |
| 362 } | 361 } |
| 363 | 362 |
| 364 }; // namespace window_manager | 363 }; // namespace window_manager |
| OLD | NEW |