| 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 "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" | 5 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 9 #include "base/message_loop/message_pump_x11.h" | |
| 10 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 12 #include "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
| 13 #include "ui/base/clipboard/clipboard.h" | 12 #include "ui/base/clipboard/clipboard.h" |
| 14 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 13 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 15 #include "ui/base/dragdrop/file_info.h" | 14 #include "ui/base/dragdrop/file_info.h" |
| 16 #include "ui/base/x/selection_utils.h" | 15 #include "ui/base/x/selection_utils.h" |
| 17 #include "ui/base/x/x11_util.h" | 16 #include "ui/base/x/x11_util.h" |
| 17 #include "ui/events/platform/platform_event_source.h" |
| 18 | 18 |
| 19 // Note: the GetBlah() methods are used immediately by the | 19 // Note: the GetBlah() methods are used immediately by the |
| 20 // web_contents_view_aura.cc:PrepareDropData(), while the omnibox is a | 20 // web_contents_view_aura.cc:PrepareDropData(), while the omnibox is a |
| 21 // little more discriminating and calls HasBlah() before trying to get the | 21 // little more discriminating and calls HasBlah() before trying to get the |
| 22 // information. | 22 // information. |
| 23 | 23 |
| 24 namespace ui { | 24 namespace ui { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 NULL)), | 76 NULL)), |
| 77 atom_cache_(x_display_, kAtomsToCache), | 77 atom_cache_(x_display_, kAtomsToCache), |
| 78 format_map_(), | 78 format_map_(), |
| 79 selection_owner_(x_display_, x_window_, | 79 selection_owner_(x_display_, x_window_, |
| 80 atom_cache_.GetAtom(kDndSelection)) { | 80 atom_cache_.GetAtom(kDndSelection)) { |
| 81 // We don't know all possible MIME types at compile time. | 81 // We don't know all possible MIME types at compile time. |
| 82 atom_cache_.allow_uncached_atoms(); | 82 atom_cache_.allow_uncached_atoms(); |
| 83 | 83 |
| 84 XStoreName(x_display_, x_window_, "Chromium Drag & Drop Window"); | 84 XStoreName(x_display_, x_window_, "Chromium Drag & Drop Window"); |
| 85 | 85 |
| 86 base::MessagePumpX11::Current()->AddDispatcherForWindow(this, x_window_); | 86 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
| 87 } | 87 } |
| 88 | 88 |
| 89 OSExchangeDataProviderAuraX11::~OSExchangeDataProviderAuraX11() { | 89 OSExchangeDataProviderAuraX11::~OSExchangeDataProviderAuraX11() { |
| 90 if (own_window_) { | 90 if (own_window_) { |
| 91 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(x_window_); | 91 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
| 92 XDestroyWindow(x_display_, x_window_); | 92 XDestroyWindow(x_display_, x_window_); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 void OSExchangeDataProviderAuraX11::TakeOwnershipOfSelection() const { | 96 void OSExchangeDataProviderAuraX11::TakeOwnershipOfSelection() const { |
| 97 selection_owner_.TakeOwnershipOfSelection(format_map_); | 97 selection_owner_.TakeOwnershipOfSelection(format_map_); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void OSExchangeDataProviderAuraX11::RetrieveTargets( | 100 void OSExchangeDataProviderAuraX11::RetrieveTargets( |
| 101 std::vector<Atom>* targets) const { | 101 std::vector<Atom>* targets) const { |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 } | 487 } |
| 488 | 488 |
| 489 const gfx::ImageSkia& OSExchangeDataProviderAuraX11::GetDragImage() const { | 489 const gfx::ImageSkia& OSExchangeDataProviderAuraX11::GetDragImage() const { |
| 490 return drag_image_; | 490 return drag_image_; |
| 491 } | 491 } |
| 492 | 492 |
| 493 const gfx::Vector2d& OSExchangeDataProviderAuraX11::GetDragImageOffset() const { | 493 const gfx::Vector2d& OSExchangeDataProviderAuraX11::GetDragImageOffset() const { |
| 494 return drag_image_offset_; | 494 return drag_image_offset_; |
| 495 } | 495 } |
| 496 | 496 |
| 497 uint32_t OSExchangeDataProviderAuraX11::Dispatch( | 497 bool OSExchangeDataProviderAuraX11::CanDispatchEvent( |
| 498 const base::NativeEvent& event) { | 498 const PlatformEvent& event) { |
| 499 return event->xany.window == x_window_; |
| 500 } |
| 501 |
| 502 uint32_t OSExchangeDataProviderAuraX11::DispatchEvent( |
| 503 const PlatformEvent& event) { |
| 499 XEvent* xev = event; | 504 XEvent* xev = event; |
| 500 switch (xev->type) { | 505 switch (xev->type) { |
| 501 case SelectionRequest: | 506 case SelectionRequest: |
| 502 selection_owner_.OnSelectionRequest(xev->xselectionrequest); | 507 selection_owner_.OnSelectionRequest(xev->xselectionrequest); |
| 503 break; | 508 return ui::POST_DISPATCH_STOP_PROPAGATION; |
| 504 default: | 509 default: |
| 505 NOTIMPLEMENTED(); | 510 NOTIMPLEMENTED(); |
| 506 } | 511 } |
| 507 | 512 return ui::POST_DISPATCH_NONE; |
| 508 return POST_DISPATCH_NONE; | |
| 509 } | 513 } |
| 510 | 514 |
| 511 bool OSExchangeDataProviderAuraX11::GetPlainTextURL(GURL* url) const { | 515 bool OSExchangeDataProviderAuraX11::GetPlainTextURL(GURL* url) const { |
| 512 base::string16 text; | 516 base::string16 text; |
| 513 if (GetString(&text)) { | 517 if (GetString(&text)) { |
| 514 GURL test_url(text); | 518 GURL test_url(text); |
| 515 if (test_url.is_valid()) { | 519 if (test_url.is_valid()) { |
| 516 *url = test_url; | 520 *url = test_url; |
| 517 return true; | 521 return true; |
| 518 } | 522 } |
| 519 } | 523 } |
| 520 | 524 |
| 521 return false; | 525 return false; |
| 522 } | 526 } |
| 523 | 527 |
| 524 std::vector< ::Atom> OSExchangeDataProviderAuraX11::GetTargets() const { | 528 std::vector< ::Atom> OSExchangeDataProviderAuraX11::GetTargets() const { |
| 525 return format_map_.GetTypes(); | 529 return format_map_.GetTypes(); |
| 526 } | 530 } |
| 527 | 531 |
| 528 /////////////////////////////////////////////////////////////////////////////// | 532 /////////////////////////////////////////////////////////////////////////////// |
| 529 // OSExchangeData, public: | 533 // OSExchangeData, public: |
| 530 | 534 |
| 531 // static | 535 // static |
| 532 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 536 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
| 533 return new OSExchangeDataProviderAuraX11(); | 537 return new OSExchangeDataProviderAuraX11(); |
| 534 } | 538 } |
| 535 | 539 |
| 536 } // namespace ui | 540 } // namespace ui |
| OLD | NEW |