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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
6 | 6 |
7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
11 | 11 |
| 12 #include "base/auto_reset.h" |
12 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "third_party/skia/include/core/SkRect.h" | 19 #include "third_party/skia/include/core/SkRect.h" |
19 #include "ui/base/accessibility/accessibility_types.h" | 20 #include "ui/base/accessibility/accessibility_types.h" |
20 #include "ui/base/dragdrop/drag_drop_types.h" | 21 #include "ui/base/dragdrop/drag_drop_types.h" |
21 #include "ui/base/ui_base_switches_util.h" | 22 #include "ui/base/ui_base_switches_util.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 paint_to_layer_(false), | 179 paint_to_layer_(false), |
179 accelerator_registration_delayed_(false), | 180 accelerator_registration_delayed_(false), |
180 accelerator_focus_manager_(NULL), | 181 accelerator_focus_manager_(NULL), |
181 registered_accelerator_count_(0), | 182 registered_accelerator_count_(0), |
182 next_focusable_view_(NULL), | 183 next_focusable_view_(NULL), |
183 previous_focusable_view_(NULL), | 184 previous_focusable_view_(NULL), |
184 focusable_(false), | 185 focusable_(false), |
185 accessibility_focusable_(false), | 186 accessibility_focusable_(false), |
186 context_menu_controller_(NULL), | 187 context_menu_controller_(NULL), |
187 drag_controller_(NULL), | 188 drag_controller_(NULL), |
| 189 currently_dragging_(false), |
188 post_dispatch_handler_(new internal::PostEventDispatchHandler(this)), | 190 post_dispatch_handler_(new internal::PostEventDispatchHandler(this)), |
189 native_view_accessibility_(NULL) { | 191 native_view_accessibility_(NULL) { |
190 AddPostTargetHandler(post_dispatch_handler_.get()); | 192 AddPostTargetHandler(post_dispatch_handler_.get()); |
191 } | 193 } |
192 | 194 |
193 View::~View() { | 195 View::~View() { |
194 if (parent_) | 196 if (parent_) |
195 parent_->RemoveChildView(this); | 197 parent_->RemoveChildView(this); |
196 | 198 |
| 199 // If we destroy the view during a drag, AutoReset will probably write to |
| 200 // freed memory. |
| 201 DCHECK(!currently_dragging_); |
| 202 |
197 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { | 203 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { |
198 (*i)->parent_ = NULL; | 204 (*i)->parent_ = NULL; |
199 if (!(*i)->owned_by_client_) | 205 if (!(*i)->owned_by_client_) |
200 delete *i; | 206 delete *i; |
201 } | 207 } |
202 | 208 |
203 // Release ownership of the native accessibility object, but it's | 209 // Release ownership of the native accessibility object, but it's |
204 // reference-counted on some platforms, so it may not be deleted right away. | 210 // reference-counted on some platforms, so it may not be deleted right away. |
205 if (native_view_accessibility_) | 211 if (native_view_accessibility_) |
206 native_view_accessibility_->Destroy(); | 212 native_view_accessibility_->Destroy(); |
(...skipping 2104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2311 if (widget && widget->native_widget_private()->GetTooltipManager()) | 2317 if (widget && widget->native_widget_private()->GetTooltipManager()) |
2312 widget->native_widget_private()->GetTooltipManager()->UpdateTooltip(); | 2318 widget->native_widget_private()->GetTooltipManager()->UpdateTooltip(); |
2313 } | 2319 } |
2314 | 2320 |
2315 // Drag and drop --------------------------------------------------------------- | 2321 // Drag and drop --------------------------------------------------------------- |
2316 | 2322 |
2317 bool View::DoDrag(const ui::LocatedEvent& event, | 2323 bool View::DoDrag(const ui::LocatedEvent& event, |
2318 const gfx::Point& press_pt, | 2324 const gfx::Point& press_pt, |
2319 ui::DragDropTypes::DragEventSource source) { | 2325 ui::DragDropTypes::DragEventSource source) { |
2320 #if !defined(OS_MACOSX) | 2326 #if !defined(OS_MACOSX) |
| 2327 if (currently_dragging_) |
| 2328 return false; |
| 2329 |
2321 int drag_operations = GetDragOperations(press_pt); | 2330 int drag_operations = GetDragOperations(press_pt); |
2322 if (drag_operations == ui::DragDropTypes::DRAG_NONE) | 2331 if (drag_operations == ui::DragDropTypes::DRAG_NONE) |
2323 return false; | 2332 return false; |
2324 | 2333 |
| 2334 base::AutoReset<bool> updating_focus(¤tly_dragging_, true); |
2325 OSExchangeData data; | 2335 OSExchangeData data; |
2326 WriteDragData(press_pt, &data); | 2336 WriteDragData(press_pt, &data); |
2327 | 2337 |
2328 // Message the RootView to do the drag and drop. That way if we're removed | 2338 // Message the RootView to do the drag and drop. That way if we're removed |
2329 // the RootView can detect it and avoid calling us back. | 2339 // the RootView can detect it and avoid calling us back. |
2330 gfx::Point widget_location(event.location()); | 2340 gfx::Point widget_location(event.location()); |
2331 ConvertPointToWidget(this, &widget_location); | 2341 ConvertPointToWidget(this, &widget_location); |
2332 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2342 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
2333 source); | 2343 source); |
| 2344 |
2334 return true; | 2345 return true; |
2335 #else | 2346 #else |
2336 return false; | 2347 return false; |
2337 #endif // !defined(OS_MACOSX) | 2348 #endif // !defined(OS_MACOSX) |
2338 } | 2349 } |
2339 | 2350 |
2340 } // namespace views | 2351 } // namespace views |
OLD | NEW |