Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ash / wm / toplevel_window_event_handler.cc
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
3 // found in the LICENSE file.
4
5 #include "ash/wm/toplevel_window_event_handler.h"
6
7 #include "ash/shell.h"
8 #include "ash/wm/resize_shadow_controller.h"
9 #include "ash/wm/window_resizer.h"
10 #include "ash/wm/window_state.h"
11 #include "ash/wm/window_state_observer.h"
12 #include "ash/wm/window_util.h"
13 #include "ash/wm/workspace/snap_sizer.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h"
16 #include "ui/aura/client/cursor_client.h"
17 #include "ui/aura/env.h"
18 #include "ui/aura/root_window.h"
19 #include "ui/aura/window.h"
20 #include "ui/aura/window_delegate.h"
21 #include "ui/aura/window_observer.h"
22 #include "ui/base/cursor/cursor.h"
23 #include "ui/base/hit_test.h"
24 #include "ui/base/ui_base_types.h"
25 #include "ui/events/event.h"
26 #include "ui/events/event_utils.h"
27 #include "ui/events/gestures/gesture_recognizer.h"
28 #include "ui/gfx/geometry/point_conversions.h"
29 #include "ui/gfx/screen.h"
30
31 namespace {
32 const double kMinHorizVelocityForWindowSwipe = 1100;
33 const double kMinVertVelocityForWindowMinimize = 1000;
34 }
35
36 namespace ash {
37
38 namespace {
39
40 // Returns whether |window| can be moved via a two finger drag given
41 // the hittest results of the two fingers.
42 bool CanStartTwoFingerMove(aura::Window* window,
43                            int window_component1,
44                            int window_component2) {
45   // We allow moving a window via two fingers when the hittest components are
46   // HTCLIENT. This is done so that a window can be dragged via two fingers when
47   // the tab strip is full and hitting the caption area is difficult. We check
48   // the window type and the show state so that we do not steal touches from the
49   // web contents.
50   if (!ash::wm::GetWindowState(window)->IsNormalShowState() ||
51       window->type() != ui::wm::WINDOW_TYPE_NORMAL) {
52     return false;
53   }
54   int component1_behavior =
55       WindowResizer::GetBoundsChangeForWindowComponent(window_component1);
56   int component2_behavior =
57       WindowResizer::GetBoundsChangeForWindowComponent(window_component2);
58   return (component1_behavior & WindowResizer::kBoundsChange_Resizes) == 0 &&
59       (component2_behavior & WindowResizer::kBoundsChange_Resizes) == 0;
60 }
61
62 // Returns whether |window| can be moved or resized via one finger given
63 // |window_component|.
64 bool CanStartOneFingerDrag(int window_component) {
65   return WindowResizer::GetBoundsChangeForWindowComponent(
66       window_component) != 0;
67 }
68
69 gfx::Point ConvertPointToParent(aura::Window* window,
70                                 const gfx::Point& point) {
71   gfx::Point result(point);
72   aura::Window::ConvertPointToTarget(window, window->parent(), &result);
73   return result;
74 }
75
76 // Returns the window component containing |event|'s location.
77 int GetWindowComponent(aura::Window* window, const ui::LocatedEvent& event) {
78   return window->delegate()->GetNonClientComponent(event.location());
79 }
80
81 }  // namespace
82
83 // ScopedWindowResizer ---------------------------------------------------------
84
85 // Wraps a WindowResizer and installs an observer on its target window.  When
86 // the window is destroyed ResizerWindowDestroyed() is invoked back on the
87 // ToplevelWindowEventHandler to clean up.
88 class ToplevelWindowEventHandler::ScopedWindowResizer
89     : public aura::WindowObserver,
90       public wm::WindowStateObserver {
91  public:
92   ScopedWindowResizer(ToplevelWindowEventHandler* handler,
93                       WindowResizer* resizer);
94   virtual ~ScopedWindowResizer();
95
96   // Returns true if the drag moves the window and does not resize.
97   bool IsMove() const;
98
99   WindowResizer* resizer() { return resizer_.get(); }
100
101   // WindowObserver overrides:
102   virtual void OnWindowHierarchyChanging(
103       const HierarchyChangeParams& params) OVERRIDE;
104   virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
105
106   // WindowStateObserver overrides:
107   virtual void OnPreWindowShowTypeChange(wm::WindowState* window_state,
108                                          wm::WindowShowType type) OVERRIDE;
109
110  private:
111   ToplevelWindowEventHandler* handler_;
112   scoped_ptr<WindowResizer> resizer_;
113
114   DISALLOW_COPY_AND_ASSIGN(ScopedWindowResizer);
115 };
116
117 ToplevelWindowEventHandler::ScopedWindowResizer::ScopedWindowResizer(
118     ToplevelWindowEventHandler* handler,
119     WindowResizer* resizer)
120     : handler_(handler),
121       resizer_(resizer) {
122   resizer_->GetTarget()->AddObserver(this);
123   wm::GetWindowState(resizer_->GetTarget())->AddObserver(this);
124 }
125
126 ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() {
127   resizer_->GetTarget()->RemoveObserver(this);
128   wm::GetWindowState(resizer_->GetTarget())->RemoveObserver(this);
129 }
130
131 bool ToplevelWindowEventHandler::ScopedWindowResizer::IsMove() const {
132   return resizer_->details().bounds_change ==
133       WindowResizer::kBoundsChange_Repositions;
134 }
135
136 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowHierarchyChanging(
137     const HierarchyChangeParams& params) {
138   if (params.receiver != resizer_->GetTarget())
139     return;
140   wm::WindowState* state = wm::GetWindowState(params.receiver);
141   if (state->continue_drag_after_reparent())
142     state->set_continue_drag_after_reparent(false);
143   else
144     handler_->CompleteDrag(DRAG_COMPLETE);
145 }
146
147 void
148 ToplevelWindowEventHandler::ScopedWindowResizer::OnPreWindowShowTypeChange(
149     wm::WindowState* window_state,
150     wm::WindowShowType old) {
151   handler_->CompleteDrag(DRAG_COMPLETE);
152 }
153
154 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying(
155     aura::Window* window) {
156   DCHECK_EQ(resizer_->GetTarget(), window);
157   handler_->ResizerWindowDestroyed();
158 }
159
160 // ToplevelWindowEventHandler --------------------------------------------------
161
162 ToplevelWindowEventHandler::ToplevelWindowEventHandler()
163     : first_finger_hittest_(HTNOWHERE),
164       in_move_loop_(false),
165       in_gesture_drag_(false),
166       drag_reverted_(false),
167       destroyed_(NULL) {
168   Shell::GetInstance()->display_controller()->AddObserver(this);
169 }
170
171 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() {
172   Shell::GetInstance()->display_controller()->RemoveObserver(this);
173   if (destroyed_)
174     *destroyed_ = true;
175 }
176
177 void ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) {
178   if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED &&
179       event->key_code() == ui::VKEY_ESCAPE) {
180     CompleteDrag(DRAG_REVERT);
181   }
182 }
183
184 void ToplevelWindowEventHandler::OnMouseEvent(
185     ui::MouseEvent* event) {
186   if (event->handled())
187     return;
188   if ((event->flags() &
189       (ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)) != 0)
190     return;
191
192   if (in_gesture_drag_)
193     return;
194
195   aura::Window* target = static_cast<aura::Window*>(event->target());
196   switch (event->type()) {
197     case ui::ET_MOUSE_PRESSED:
198       HandleMousePressed(target, event);
199       break;
200     case ui::ET_MOUSE_DRAGGED:
201       HandleDrag(target, event);
202       break;
203     case ui::ET_MOUSE_CAPTURE_CHANGED:
204     case ui::ET_MOUSE_RELEASED:
205       HandleMouseReleased(target, event);
206       break;
207     case ui::ET_MOUSE_MOVED:
208       HandleMouseMoved(target, event);
209       break;
210     case ui::ET_MOUSE_EXITED:
211       HandleMouseExited(target, event);
212       break;
213     default:
214       break;
215   }
216 }
217
218 void ToplevelWindowEventHandler::OnGestureEvent(ui::GestureEvent* event) {
219   if (event->handled())
220     return;
221   aura::Window* target = static_cast<aura::Window*>(event->target());
222   if (!target->delegate())
223     return;
224
225   if (window_resizer_.get() && !in_gesture_drag_)
226     return;
227
228   if (window_resizer_.get() &&
229       window_resizer_->resizer()->GetTarget() != target) {
230     return;
231   }
232
233   if (event->details().touch_points() > 2) {
234     if (window_resizer_.get()) {
235       CompleteDrag(DRAG_COMPLETE);
236       event->StopPropagation();
237     }
238     return;
239   }
240
241   switch (event->type()) {
242     case ui::ET_GESTURE_TAP_DOWN: {
243       int component = GetWindowComponent(target, *event);
244       if (!(WindowResizer::GetBoundsChangeForWindowComponent(component) &
245             WindowResizer::kBoundsChange_Resizes))
246         return;
247       internal::ResizeShadowController* controller =
248           Shell::GetInstance()->resize_shadow_controller();
249       if (controller)
250         controller->ShowShadow(target, component);
251       return;
252     }
253     case ui::ET_GESTURE_END: {
254       internal::ResizeShadowController* controller =
255           Shell::GetInstance()->resize_shadow_controller();
256       if (controller)
257         controller->HideShadow(target);
258
259       if (window_resizer_.get() &&
260           (event->details().touch_points() == 1 ||
261            !CanStartOneFingerDrag(first_finger_hittest_))) {
262         CompleteDrag(DRAG_COMPLETE);
263         event->StopPropagation();
264       }
265       return;
266     }
267     case ui::ET_GESTURE_BEGIN: {
268       if (event->details().touch_points() == 1) {
269         first_finger_hittest_ = GetWindowComponent(target, *event);
270       } else if (window_resizer_.get()) {
271         if (!window_resizer_->IsMove()) {
272           // The transition from resizing with one finger to resizing with two
273           // fingers causes unintended resizing because the location of
274           // ET_GESTURE_SCROLL_UPDATE jumps from the position of the first
275           // finger to the position in the middle of the two fingers. For this
276           // reason two finger resizing is not supported.
277           CompleteDrag(DRAG_COMPLETE);
278           event->StopPropagation();
279         }
280       } else {
281         int second_finger_hittest = GetWindowComponent(target, *event);
282         if (CanStartTwoFingerMove(
283                 target, first_finger_hittest_, second_finger_hittest)) {
284           gfx::Point location_in_parent =
285               event->details().bounding_box().CenterPoint();
286           AttemptToStartDrag(target, location_in_parent, HTCAPTION,
287                              aura::client::WINDOW_MOVE_SOURCE_TOUCH);
288           event->StopPropagation();
289         }
290       }
291       return;
292     }
293     case ui::ET_GESTURE_SCROLL_BEGIN: {
294       // The one finger drag is not started in ET_GESTURE_BEGIN to avoid the
295       // window jumping upon initiating a two finger drag. When a one finger
296       // drag is converted to a two finger drag, a jump occurs because the
297       // location of the ET_GESTURE_SCROLL_UPDATE event switches from the single
298       // finger's position to the position in the middle of the two fingers.
299       if (window_resizer_.get())
300         return;
301       int component = GetWindowComponent(target, *event);
302       if (!CanStartOneFingerDrag(component))
303         return;
304       gfx::Point location_in_parent(
305           ConvertPointToParent(target, event->location()));
306       AttemptToStartDrag(target, location_in_parent, component,
307                          aura::client::WINDOW_MOVE_SOURCE_TOUCH);
308       event->StopPropagation();
309       return;
310     }
311     default:
312       break;
313   }
314
315   if (!window_resizer_.get())
316     return;
317
318   switch (event->type()) {
319     case ui::ET_GESTURE_SCROLL_UPDATE:
320       HandleDrag(target, event);
321       event->StopPropagation();
322       return;
323     case ui::ET_GESTURE_SCROLL_END:
324       // We must complete the drag here instead of as a result of ET_GESTURE_END
325       // because otherwise the drag will be reverted when EndMoveLoop() is
326       // called.
327       // TODO(pkotwicz): Pass drag completion status to
328       // WindowMoveClient::EndMoveLoop().
329       CompleteDrag(DRAG_COMPLETE);
330       event->StopPropagation();
331       return;
332     case ui::ET_SCROLL_FLING_START:
333       CompleteDrag(DRAG_COMPLETE);
334
335       // TODO(pkotwicz): Fix tests which inadvertantly start flings and check
336       // window_resizer_->IsMove() instead of the hittest component at |event|'s
337       // location.
338       if (GetWindowComponent(target, *event) != HTCAPTION ||
339           !wm::GetWindowState(target)->IsNormalShowState()) {
340         return;
341       }
342
343       if (event->details().velocity_y() > kMinVertVelocityForWindowMinimize) {
344         SetWindowShowTypeFromGesture(target, wm::SHOW_TYPE_MINIMIZED);
345       } else if (event->details().velocity_y() <
346                  -kMinVertVelocityForWindowMinimize) {
347         SetWindowShowTypeFromGesture(target, wm::SHOW_TYPE_MAXIMIZED);
348       } else if (event->details().velocity_x() >
349                  kMinHorizVelocityForWindowSwipe) {
350         SetWindowShowTypeFromGesture(target, wm::SHOW_TYPE_RIGHT_SNAPPED);
351       } else if (event->details().velocity_x() <
352                  -kMinHorizVelocityForWindowSwipe) {
353         SetWindowShowTypeFromGesture(target, wm::SHOW_TYPE_LEFT_SNAPPED);
354       }
355       event->StopPropagation();
356       return;
357     case ui::ET_GESTURE_MULTIFINGER_SWIPE:
358       if (!wm::GetWindowState(target)->IsNormalShowState())
359         return;
360
361       CompleteDrag(DRAG_COMPLETE);
362
363       if (event->details().swipe_down())
364         SetWindowShowTypeFromGesture(target, wm::SHOW_TYPE_MINIMIZED);
365       else if (event->details().swipe_up())
366         SetWindowShowTypeFromGesture(target, wm::SHOW_TYPE_MAXIMIZED);
367       else if (event->details().swipe_right())
368         SetWindowShowTypeFromGesture(target, wm::SHOW_TYPE_RIGHT_SNAPPED);
369       else
370         SetWindowShowTypeFromGesture(target, wm::SHOW_TYPE_LEFT_SNAPPED);
371       event->StopPropagation();
372       return;
373     default:
374       return;
375   }
376 }
377
378 aura::client::WindowMoveResult ToplevelWindowEventHandler::RunMoveLoop(
379     aura::Window* source,
380     const gfx::Vector2d& drag_offset,
381     aura::client::WindowMoveSource move_source) {
382   DCHECK(!in_move_loop_);  // Can only handle one nested loop at a time.
383   aura::Window* root_window = source->GetRootWindow();
384   DCHECK(root_window);
385   // TODO(tdresser): Use gfx::PointF. See crbug.com/337824.
386   gfx::Point drag_location;
387   if (move_source == aura::client::WINDOW_MOVE_SOURCE_TOUCH &&
388       aura::Env::GetInstance()->is_touch_down()) {
389     gfx::PointF drag_location_f;
390     bool has_point = ui::GestureRecognizer::Get()->
391         GetLastTouchPointForTarget(source, &drag_location_f);
392     drag_location = gfx::ToFlooredPoint(drag_location_f);
393     DCHECK(has_point);
394   } else {
395     drag_location = root_window->GetDispatcher()->GetLastMouseLocationInRoot();
396     aura::Window::ConvertPointToTarget(
397         root_window, source->parent(), &drag_location);
398   }
399   // Set the cursor before calling AttemptToStartDrag(), as that will
400   // eventually call LockCursor() and prevent the cursor from changing.
401   aura::client::CursorClient* cursor_client =
402       aura::client::GetCursorClient(root_window);
403   if (cursor_client)
404     cursor_client->SetCursor(ui::kCursorPointer);
405   if (!AttemptToStartDrag(source, drag_location, HTCAPTION, move_source))
406     return aura::client::MOVE_CANCELED;
407
408   in_move_loop_ = true;
409   bool destroyed = false;
410   destroyed_ = &destroyed;
411   base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
412   base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
413   base::RunLoop run_loop;
414   quit_closure_ = run_loop.QuitClosure();
415   run_loop.Run();
416   if (destroyed)
417     return aura::client::MOVE_CANCELED;
418   destroyed_ = NULL;
419   in_move_loop_ = false;
420   return drag_reverted_ ? aura::client::MOVE_CANCELED :
421       aura::client::MOVE_SUCCESSFUL;
422 }
423
424 void ToplevelWindowEventHandler::EndMoveLoop() {
425   if (in_move_loop_)
426     CompleteDrag(DRAG_REVERT);
427 }
428
429 void ToplevelWindowEventHandler::OnDisplayConfigurationChanging() {
430   CompleteDrag(DRAG_REVERT);
431 }
432
433 bool ToplevelWindowEventHandler::AttemptToStartDrag(
434     aura::Window* window,
435     const gfx::Point& point_in_parent,
436     int window_component,
437     aura::client::WindowMoveSource source) {
438   if (window_resizer_.get())
439     return false;
440   WindowResizer* resizer = CreateWindowResizer(window, point_in_parent,
441       window_component, source).release();
442   if (!resizer)
443     return false;
444
445   window_resizer_.reset(new ScopedWindowResizer(this, resizer));
446
447   pre_drag_window_bounds_ = window->bounds();
448   in_gesture_drag_ = (source == aura::client::WINDOW_MOVE_SOURCE_TOUCH);
449   return true;
450 }
451
452 void ToplevelWindowEventHandler::CompleteDrag(DragCompletionStatus status) {
453   scoped_ptr<ScopedWindowResizer> resizer(window_resizer_.release());
454   if (resizer) {
455     if (status == DRAG_COMPLETE)
456       resizer->resizer()->CompleteDrag();
457     else
458       resizer->resizer()->RevertDrag();
459   }
460   drag_reverted_ = (status == DRAG_REVERT);
461
462   first_finger_hittest_ = HTNOWHERE;
463   in_gesture_drag_ = false;
464   if (in_move_loop_)
465     quit_closure_.Run();
466 }
467
468 void ToplevelWindowEventHandler::HandleMousePressed(
469     aura::Window* target,
470     ui::MouseEvent* event) {
471   if (event->phase() != ui::EP_PRETARGET || !target->delegate())
472     return;
473
474   // We also update the current window component here because for the
475   // mouse-drag-release-press case, where the mouse is released and
476   // pressed without mouse move event.
477   int component = GetWindowComponent(target, *event);
478   if ((event->flags() &
479         (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0 &&
480       WindowResizer::GetBoundsChangeForWindowComponent(component)) {
481     gfx::Point location_in_parent(
482         ConvertPointToParent(target, event->location()));
483     AttemptToStartDrag(target, location_in_parent, component,
484                        aura::client::WINDOW_MOVE_SOURCE_MOUSE);
485     event->StopPropagation();
486   } else {
487     CompleteDrag(DRAG_COMPLETE);
488   }
489 }
490
491 void ToplevelWindowEventHandler::HandleMouseReleased(
492     aura::Window* target,
493     ui::MouseEvent* event) {
494   if (event->phase() != ui::EP_PRETARGET)
495     return;
496
497   CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ?
498                    DRAG_COMPLETE : DRAG_REVERT);
499   // Completing the drag may result in hiding the window. If this happens
500   // return true so no other handlers/observers see the event. Otherwise
501   // they see the event on a hidden window.
502   if (window_resizer_ &&
503       event->type() == ui::ET_MOUSE_CAPTURE_CHANGED &&
504       !target->IsVisible()) {
505     event->StopPropagation();
506   }
507 }
508
509 void ToplevelWindowEventHandler::HandleDrag(
510     aura::Window* target,
511     ui::LocatedEvent* event) {
512   // This function only be triggered to move window
513   // by mouse drag or touch move event.
514   DCHECK(event->type() == ui::ET_MOUSE_DRAGGED ||
515          event->type() == ui::ET_TOUCH_MOVED ||
516          event->type() == ui::ET_GESTURE_SCROLL_UPDATE);
517
518   // Drag actions are performed pre-target handling to prevent spurious mouse
519   // moves from the move/size operation from being sent to the target.
520   if (event->phase() != ui::EP_PRETARGET)
521     return;
522
523   if (!window_resizer_)
524     return;
525   window_resizer_->resizer()->Drag(
526       ConvertPointToParent(target, event->location()), event->flags());
527   event->StopPropagation();
528 }
529
530 void ToplevelWindowEventHandler::HandleMouseMoved(
531     aura::Window* target,
532     ui::LocatedEvent* event) {
533   // Shadow effects are applied after target handling. Note that we don't
534   // respect ER_HANDLED here right now since we have not had a reason to allow
535   // the target to cancel shadow rendering.
536   if (event->phase() != ui::EP_POSTTARGET || !target->delegate())
537     return;
538
539   // TODO(jamescook): Move the resize cursor update code into here from
540   // CompoundEventFilter?
541   internal::ResizeShadowController* controller =
542       Shell::GetInstance()->resize_shadow_controller();
543   if (controller) {
544     if (event->flags() & ui::EF_IS_NON_CLIENT) {
545       int component =
546           target->delegate()->GetNonClientComponent(event->location());
547       controller->ShowShadow(target, component);
548     } else {
549       controller->HideShadow(target);
550     }
551   }
552 }
553
554 void ToplevelWindowEventHandler::HandleMouseExited(
555     aura::Window* target,
556     ui::LocatedEvent* event) {
557   // Shadow effects are applied after target handling. Note that we don't
558   // respect ER_HANDLED here right now since we have not had a reason to allow
559   // the target to cancel shadow rendering.
560   if (event->phase() != ui::EP_POSTTARGET)
561     return;
562
563   internal::ResizeShadowController* controller =
564       Shell::GetInstance()->resize_shadow_controller();
565   if (controller)
566     controller->HideShadow(target);
567 }
568
569 void ToplevelWindowEventHandler::SetWindowShowTypeFromGesture(
570     aura::Window* window,
571     wm::WindowShowType new_show_type) {
572   wm::WindowState* window_state = ash::wm::GetWindowState(window);
573   switch (new_show_type) {
574     case wm::SHOW_TYPE_MINIMIZED:
575       if (window_state->CanMinimize()) {
576         window_state->Minimize();
577         window_state->set_unminimize_to_restore_bounds(true);
578         window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_);
579       }
580       break;
581     case wm::SHOW_TYPE_MAXIMIZED:
582       if (window_state->CanMaximize()) {
583         window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_);
584         window_state->Maximize();
585       }
586       break;
587     case wm::SHOW_TYPE_LEFT_SNAPPED:
588       if (window_state->CanSnap()) {
589         window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_);
590         internal::SnapSizer::SnapWindow(window_state,
591                                         internal::SnapSizer::LEFT_EDGE);
592       }
593       break;
594     case wm::SHOW_TYPE_RIGHT_SNAPPED:
595       if (window_state->CanSnap()) {
596         window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_);
597         internal::SnapSizer::SnapWindow(window_state,
598                                         internal::SnapSizer::RIGHT_EDGE);
599       }
600       break;
601     default:
602       NOTREACHED();
603   }
604 }
605
606 void ToplevelWindowEventHandler::ResizerWindowDestroyed() {
607   // We explicitly don't invoke RevertDrag() since that may do things to window.
608   // Instead we destroy the resizer.
609   window_resizer_.reset();
610
611   CompleteDrag(DRAG_REVERT);
612 }
613
614 }  // namespace ash