OLD | NEW |
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/wm/workspace/frame_maximize_button.h" | 5 #include "ash/wm/workspace/frame_maximize_button.h" |
6 | 6 |
7 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/wm/property_util.h" | 9 #include "ash/wm/property_util.h" |
10 #include "ash/launcher/launcher.h" | 10 #include "ash/launcher/launcher.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 return ui::GESTURE_STATUS_UNKNOWN; | 89 return ui::GESTURE_STATUS_UNKNOWN; |
90 } | 90 } |
91 | 91 |
92 // FrameMaximizeButton --------------------------------------------------------- | 92 // FrameMaximizeButton --------------------------------------------------------- |
93 | 93 |
94 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener, | 94 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener, |
95 views::NonClientFrameView* frame) | 95 views::NonClientFrameView* frame) |
96 : ImageButton(listener), | 96 : ImageButton(listener), |
97 frame_(frame), | 97 frame_(frame), |
98 is_snap_enabled_(false), | 98 is_snap_enabled_(false), |
| 99 is_left_right_enabled_(true), |
| 100 is_maximize_enabled_(true), |
99 exceeded_drag_threshold_(false), | 101 exceeded_drag_threshold_(false), |
100 snap_type_(SNAP_NONE) { | 102 snap_type_(SNAP_NONE) { |
101 // TODO(sky): nuke this. It's temporary while we don't have good images. | 103 // TODO(sky): nuke this. It's temporary while we don't have good images. |
102 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); | 104 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); |
103 SetTooltipText(l10n_util::GetStringUTF16(IDS_FRAME_MAXIMIZE_BUTTON_TOOLTIP)); | 105 SetTooltipText(l10n_util::GetStringUTF16(IDS_FRAME_MAXIMIZE_BUTTON_TOOLTIP)); |
104 } | 106 } |
105 | 107 |
106 FrameMaximizeButton::~FrameMaximizeButton() { | 108 FrameMaximizeButton::~FrameMaximizeButton() { |
107 } | 109 } |
108 | 110 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } else { | 157 } else { |
156 ImageButton::OnMouseReleased(event); | 158 ImageButton::OnMouseReleased(event); |
157 } | 159 } |
158 } | 160 } |
159 | 161 |
160 void FrameMaximizeButton::OnMouseCaptureLost() { | 162 void FrameMaximizeButton::OnMouseCaptureLost() { |
161 Cancel(); | 163 Cancel(); |
162 ImageButton::OnMouseCaptureLost(); | 164 ImageButton::OnMouseCaptureLost(); |
163 } | 165 } |
164 | 166 |
| 167 void FrameMaximizeButton::SetIsLeftRightEnabled(bool e) { |
| 168 is_left_right_enabled_ = e; |
| 169 int id = is_left_right_enabled_ ? |
| 170 IDS_FRAME_MAXIMIZE_BUTTON_TOOLTIP : |
| 171 IDS_FRAME_MAXIMIZE_BUTTON_NO_SIDE_SNAP_TOOLTIP; |
| 172 SetTooltipText(l10n_util::GetStringUTF16(id)); |
| 173 } |
| 174 |
165 SkBitmap FrameMaximizeButton::GetImageToPaint() { | 175 SkBitmap FrameMaximizeButton::GetImageToPaint() { |
166 if (is_snap_enabled_) { | 176 if (is_snap_enabled_) { |
167 int id = 0; | 177 int id = 0; |
168 if (frame_->GetWidget()->IsMaximized()) { | 178 if (frame_->GetWidget()->IsMaximized()) { |
169 switch (snap_type_) { | 179 switch (snap_type_) { |
170 case SNAP_LEFT: | 180 case SNAP_LEFT: |
171 id = IDR_AURA_WINDOW_MAXIMIZED_RESTORE_SNAP_LEFT_P; | 181 id = IDR_AURA_WINDOW_MAXIMIZED_RESTORE_SNAP_LEFT_P; |
172 break; | 182 break; |
173 case SNAP_RIGHT: | 183 case SNAP_RIGHT: |
174 id = IDR_AURA_WINDOW_MAXIMIZED_RESTORE_SNAP_RIGHT_P; | 184 id = IDR_AURA_WINDOW_MAXIMIZED_RESTORE_SNAP_RIGHT_P; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 snap_edge, grid_size)); | 264 snap_edge, grid_size)); |
255 } | 265 } |
256 if (!phantom_window_.get()) { | 266 if (!phantom_window_.get()) { |
257 phantom_window_.reset(new internal::PhantomWindowController( | 267 phantom_window_.reset(new internal::PhantomWindowController( |
258 frame_->GetWidget()->GetNativeWindow(), | 268 frame_->GetWidget()->GetNativeWindow(), |
259 internal::PhantomWindowController::TYPE_EDGE, 0)); | 269 internal::PhantomWindowController::TYPE_EDGE, 0)); |
260 } | 270 } |
261 phantom_window_->Show(BoundsForType(snap_type_)); | 271 phantom_window_->Show(BoundsForType(snap_type_)); |
262 } | 272 } |
263 | 273 |
| 274 bool FrameMaximizeButton::AllowMaximize() const { |
| 275 return !frame_->GetWidget()->IsMaximized() && is_maximize_enabled_; |
| 276 } |
| 277 |
264 FrameMaximizeButton::SnapType FrameMaximizeButton::SnapTypeForLocation( | 278 FrameMaximizeButton::SnapType FrameMaximizeButton::SnapTypeForLocation( |
265 const gfx::Point& location) const { | 279 const gfx::Point& location) const { |
266 int delta_x = location.x() - press_location_.x(); | 280 int delta_x = location.x() - press_location_.x(); |
267 int delta_y = location.y() - press_location_.y(); | 281 int delta_y = location.y() - press_location_.y(); |
268 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) | 282 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) |
269 return frame_->GetWidget()->IsMaximized() ? SNAP_NONE : SNAP_MAXIMIZE; | 283 return AllowMaximize() ? SNAP_MAXIMIZE : SNAP_NONE; |
270 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) | 284 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) |
271 return SNAP_LEFT; | 285 return is_left_right_enabled_ ? SNAP_LEFT : SNAP_NONE; |
272 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) | 286 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) |
273 return SNAP_RIGHT; | 287 return is_left_right_enabled_ ? SNAP_RIGHT : SNAP_NONE; |
274 else if (delta_y > 0) | 288 else if (delta_y > 0) |
275 return SNAP_MINIMIZE; | 289 return SNAP_MINIMIZE; |
276 return frame_->GetWidget()->IsMaximized() ? SNAP_NONE : SNAP_MAXIMIZE; | 290 else if (AllowMaximize()) |
| 291 return SNAP_MAXIMIZE; |
| 292 return SNAP_NONE; |
277 } | 293 } |
278 | 294 |
279 gfx::Rect FrameMaximizeButton::BoundsForType(SnapType type) const { | 295 gfx::Rect FrameMaximizeButton::BoundsForType(SnapType type) const { |
280 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); | 296 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); |
281 switch (type) { | 297 switch (type) { |
282 case SNAP_LEFT: | 298 case SNAP_LEFT: |
283 case SNAP_RIGHT: | 299 case SNAP_RIGHT: |
284 return snap_sizer_->target_bounds(); | 300 return snap_sizer_->target_bounds(); |
285 case SNAP_MAXIMIZE: | 301 case SNAP_MAXIMIZE: |
286 return ScreenAsh::GetMaximizedWindowBounds(window); | 302 return ScreenAsh::GetMaximizedWindowBounds(window); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 break; | 341 break; |
326 case SNAP_MINIMIZE: | 342 case SNAP_MINIMIZE: |
327 frame_->GetWidget()->Minimize(); | 343 frame_->GetWidget()->Minimize(); |
328 break; | 344 break; |
329 default: | 345 default: |
330 NOTREACHED(); | 346 NOTREACHED(); |
331 } | 347 } |
332 } | 348 } |
333 | 349 |
334 } // namespace ash | 350 } // namespace ash |
OLD | NEW |