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_) |
sadrul
2013/08/14 22:49:28
Can you add a DCHECK(!currently_dragging_) here (w
| |
195 parent_->RemoveChildView(this); | 197 parent_->RemoveChildView(this); |
196 | 198 |
197 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { | 199 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { |
198 (*i)->parent_ = NULL; | 200 (*i)->parent_ = NULL; |
199 if (!(*i)->owned_by_client_) | 201 if (!(*i)->owned_by_client_) |
200 delete *i; | 202 delete *i; |
201 } | 203 } |
202 | 204 |
203 // Release ownership of the native accessibility object, but it's | 205 // Release ownership of the native accessibility object, but it's |
204 // reference-counted on some platforms, so it may not be deleted right away. | 206 // reference-counted on some platforms, so it may not be deleted right away. |
(...skipping 2106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2311 if (widget && widget->native_widget_private()->GetTooltipManager()) | 2313 if (widget && widget->native_widget_private()->GetTooltipManager()) |
2312 widget->native_widget_private()->GetTooltipManager()->UpdateTooltip(); | 2314 widget->native_widget_private()->GetTooltipManager()->UpdateTooltip(); |
2313 } | 2315 } |
2314 | 2316 |
2315 // Drag and drop --------------------------------------------------------------- | 2317 // Drag and drop --------------------------------------------------------------- |
2316 | 2318 |
2317 bool View::DoDrag(const ui::LocatedEvent& event, | 2319 bool View::DoDrag(const ui::LocatedEvent& event, |
2318 const gfx::Point& press_pt, | 2320 const gfx::Point& press_pt, |
2319 ui::DragDropTypes::DragEventSource source) { | 2321 ui::DragDropTypes::DragEventSource source) { |
2320 #if !defined(OS_MACOSX) | 2322 #if !defined(OS_MACOSX) |
2323 if (currently_dragging_) | |
2324 return false; | |
2325 | |
2321 int drag_operations = GetDragOperations(press_pt); | 2326 int drag_operations = GetDragOperations(press_pt); |
2322 if (drag_operations == ui::DragDropTypes::DRAG_NONE) | 2327 if (drag_operations == ui::DragDropTypes::DRAG_NONE) |
2323 return false; | 2328 return false; |
2324 | 2329 |
2330 base::AutoReset<bool> updating_focus(¤tly_dragging_, true); | |
2325 OSExchangeData data; | 2331 OSExchangeData data; |
2326 WriteDragData(press_pt, &data); | 2332 WriteDragData(press_pt, &data); |
2327 | 2333 |
2328 // Message the RootView to do the drag and drop. That way if we're removed | 2334 // 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. | 2335 // the RootView can detect it and avoid calling us back. |
2330 gfx::Point widget_location(event.location()); | 2336 gfx::Point widget_location(event.location()); |
2331 ConvertPointToWidget(this, &widget_location); | 2337 ConvertPointToWidget(this, &widget_location); |
2332 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2338 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
2333 source); | 2339 source); |
2340 | |
2334 return true; | 2341 return true; |
2335 #else | 2342 #else |
2336 return false; | 2343 return false; |
2337 #endif // !defined(OS_MACOSX) | 2344 #endif // !defined(OS_MACOSX) |
2338 } | 2345 } |
2339 | 2346 |
2340 } // namespace views | 2347 } // namespace views |
OLD | NEW |