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

Side by Side Diff: ash/shelf/shelf_widget.cc

Issue 118553004: aura: Add an EasyResizeWindowTargeter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-r243131 Created 6 years, 11 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/shelf/shelf_layout_manager.h ('k') | ash/shelf/shelf_widget_unittest.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/shelf/shelf_widget.h" 5 #include "ash/shelf/shelf_widget.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/focus_cycler.h" 8 #include "ash/focus_cycler.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/session_state_delegate.h" 10 #include "ash/session_state_delegate.h"
(...skipping 19 matching lines...) Expand all
30 #include "ui/compositor/layer.h" 30 #include "ui/compositor/layer.h"
31 #include "ui/compositor/scoped_layer_animation_settings.h" 31 #include "ui/compositor/scoped_layer_animation_settings.h"
32 #include "ui/events/event_constants.h" 32 #include "ui/events/event_constants.h"
33 #include "ui/gfx/canvas.h" 33 #include "ui/gfx/canvas.h"
34 #include "ui/gfx/image/image.h" 34 #include "ui/gfx/image/image.h"
35 #include "ui/gfx/image/image_skia_operations.h" 35 #include "ui/gfx/image/image_skia_operations.h"
36 #include "ui/gfx/skbitmap_operations.h" 36 #include "ui/gfx/skbitmap_operations.h"
37 #include "ui/views/accessible_pane_view.h" 37 #include "ui/views/accessible_pane_view.h"
38 #include "ui/views/widget/widget.h" 38 #include "ui/views/widget/widget.h"
39 #include "ui/views/widget/widget_delegate.h" 39 #include "ui/views/widget/widget_delegate.h"
40 #include "ui/wm/public/easy_resize_window_targeter.h"
40 41
41 namespace { 42 namespace {
42 // Size of black border at bottom (or side) of shelf. 43 // Size of black border at bottom (or side) of shelf.
43 const int kNumBlackPixels = 3; 44 const int kNumBlackPixels = 3;
44 // Alpha to paint dimming image with. 45 // Alpha to paint dimming image with.
45 const int kDimAlpha = 128; 46 const int kDimAlpha = 128;
46 47
47 // The time to dim and un-dim. 48 // The time to dim and un-dim.
48 const int kTimeToDimMs = 3000; // Slow in dimming. 49 const int kTimeToDimMs = 3000; // Slow in dimming.
49 const int kTimeToUnDimMs = 200; // Fast in activating. 50 const int kTimeToUnDimMs = 200; // Fast in activating.
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 bool touch_inside = false; 227 bool touch_inside = false;
227 if (event->type() != ui::ET_TOUCH_RELEASED && 228 if (event->type() != ui::ET_TOUCH_RELEASED &&
228 event->type() != ui::ET_TOUCH_CANCELLED) 229 event->type() != ui::ET_TOUCH_CANCELLED)
229 touch_inside = owner_->GetBoundsInScreen().Contains(event->root_location()); 230 touch_inside = owner_->GetBoundsInScreen().Contains(event->root_location());
230 231
231 if (mouse_inside_ || touch_inside_ != mouse_inside_ || touch_inside) 232 if (mouse_inside_ || touch_inside_ != mouse_inside_ || touch_inside)
232 owner_->SetHovered(mouse_inside_ || touch_inside); 233 owner_->SetHovered(mouse_inside_ || touch_inside);
233 touch_inside_ = touch_inside; 234 touch_inside_ = touch_inside;
234 } 235 }
235 236
237 using ash::internal::ShelfLayoutManager;
238
239 // ShelfWindowTargeter makes it easier to resize windows with the mouse when the
240 // window-edge slightly overlaps with the shelf edge. The targeter also makes it
241 // easier to drag the shelf out with touch while it is hidden.
242 class ShelfWindowTargeter : public wm::EasyResizeWindowTargeter,
243 public ash::ShelfLayoutManagerObserver {
244 public:
245 ShelfWindowTargeter(aura::Window* container,
246 ShelfLayoutManager* shelf)
247 : wm::EasyResizeWindowTargeter(container, gfx::Insets(), gfx::Insets()),
248 shelf_(shelf) {
249 WillChangeVisibilityState(shelf_->visibility_state());
250 shelf_->AddObserver(this);
251 }
252
253 virtual ~ShelfWindowTargeter() {
254 // |shelf_| may have been destroyed by this time.
255 if (shelf_)
256 shelf_->RemoveObserver(this);
257 }
258
259 private:
260 gfx::Insets GetInsetsForAlignment(int distance,
261 ash::ShelfAlignment alignment) {
262 switch (alignment) {
263 case ash::SHELF_ALIGNMENT_BOTTOM:
264 return gfx::Insets(distance, 0, 0, 0);
265 case ash::SHELF_ALIGNMENT_LEFT:
266 return gfx::Insets(0, 0, 0, distance);
267 case ash::SHELF_ALIGNMENT_RIGHT:
268 return gfx::Insets(0, distance, 0, 0);
269 case ash::SHELF_ALIGNMENT_TOP:
270 return gfx::Insets(0, 0, distance, 0);
271 }
272 NOTREACHED();
273 return gfx::Insets();
274 }
275
276 // ash::ShelfLayoutManagerObserver:
277 virtual void WillDeleteShelf() OVERRIDE {
278 shelf_ = NULL;
279 }
280
281 virtual void WillChangeVisibilityState(
282 ash::ShelfVisibilityState new_state) OVERRIDE {
283 gfx::Insets mouse_insets;
284 gfx::Insets touch_insets;
285 if (new_state == ash::SHELF_VISIBLE) {
286 // Let clicks at the very top of the shelf through so windows can be
287 // resized with the bottom-right corner and bottom edge.
288 mouse_insets = GetInsetsForAlignment(
289 ShelfLayoutManager::kWorkspaceAreaVisibleInset,
290 shelf_->GetAlignment());
291 } else if (new_state == ash::SHELF_AUTO_HIDE) {
292 // Extend the touch hit target out a bit to allow users to drag shelf out
293 // while hidden.
294 touch_insets = GetInsetsForAlignment(
295 -ShelfLayoutManager::kWorkspaceAreaAutoHideInset,
296 shelf_->GetAlignment());
297 }
298
299 set_mouse_extend(mouse_insets);
300 set_touch_extend(touch_insets);
301 }
302
303 ShelfLayoutManager* shelf_;
304
305 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter);
306 };
307
236 } // namespace 308 } // namespace
237 309
238 namespace ash { 310 namespace ash {
239 311
240 // The contents view of the Shelf. This view contains ShelfView and 312 // The contents view of the Shelf. This view contains ShelfView and
241 // sizes it to the width of the shelf minus the size of the status area. 313 // sizes it to the width of the shelf minus the size of the status area.
242 class ShelfWidget::DelegateView : public views::WidgetDelegate, 314 class ShelfWidget::DelegateView : public views::WidgetDelegate,
243 public views::AccessiblePaneView, 315 public views::AccessiblePaneView,
244 public internal::BackgroundAnimatorDelegate, 316 public internal::BackgroundAnimatorDelegate,
245 public aura::WindowObserver { 317 public aura::WindowObserver {
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 629
558 shelf_layout_manager_ = new internal::ShelfLayoutManager(this); 630 shelf_layout_manager_ = new internal::ShelfLayoutManager(this);
559 shelf_layout_manager_->AddObserver(this); 631 shelf_layout_manager_->AddObserver(this);
560 shelf_container->SetLayoutManager(shelf_layout_manager_); 632 shelf_container->SetLayoutManager(shelf_layout_manager_);
561 shelf_layout_manager_->set_workspace_controller(workspace_controller); 633 shelf_layout_manager_->set_workspace_controller(workspace_controller);
562 workspace_controller->SetShelf(shelf_layout_manager_); 634 workspace_controller->SetShelf(shelf_layout_manager_);
563 635
564 status_container->SetLayoutManager( 636 status_container->SetLayoutManager(
565 new internal::StatusAreaLayoutManager(this)); 637 new internal::StatusAreaLayoutManager(this));
566 638
639 shelf_container->set_event_targeter(scoped_ptr<ui::EventTargeter>(new
640 ShelfWindowTargeter(shelf_container, shelf_layout_manager_)));
641 status_container->set_event_targeter(scoped_ptr<ui::EventTargeter>(new
642 ShelfWindowTargeter(status_container, shelf_layout_manager_)));
643
567 views::Widget::AddObserver(this); 644 views::Widget::AddObserver(this);
568 } 645 }
569 646
570 ShelfWidget::~ShelfWidget() { 647 ShelfWidget::~ShelfWidget() {
571 RemoveObserver(this); 648 RemoveObserver(this);
572 } 649 }
573 650
574 void ShelfWidget::SetPaintsBackground( 651 void ShelfWidget::SetPaintsBackground(
575 ShelfBackgroundType background_type, 652 ShelfBackgroundType background_type,
576 BackgroundAnimatorChangeType change_type) { 653 BackgroundAnimatorChangeType change_type) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 DCHECK(delegate_view_); 808 DCHECK(delegate_view_);
732 return delegate_view_->disable_dimming_animations_for_test(); 809 return delegate_view_->disable_dimming_animations_for_test();
733 } 810 }
734 811
735 void ShelfWidget::WillDeleteShelf() { 812 void ShelfWidget::WillDeleteShelf() {
736 shelf_layout_manager_->RemoveObserver(this); 813 shelf_layout_manager_->RemoveObserver(this);
737 shelf_layout_manager_ = NULL; 814 shelf_layout_manager_ = NULL;
738 } 815 }
739 816
740 } // namespace ash 817 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_layout_manager.h ('k') | ash/shelf/shelf_widget_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698