This source file includes following definitions.
- forwarding_to_tab_strip_
- GetDropFormats
- AreDropTypesRequired
- CanDrop
- OnDragEntered
- OnDragUpdated
- OnDragExited
- OnPerformDrop
- GetClassName
- OnMouseWheel
- DispatchGestureEvent
- ShouldForwardToTabStrip
- MapEventToTabStrip
- tabstrip
- GetPasteAndGoURL
#include "chrome/browser/ui/views/frame/browser_root_view.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_input.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/touch_uma/touch_uma.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data.h"
const char BrowserRootView::kViewClassName[] =
"browser/ui/views/frame/BrowserRootView";
BrowserRootView::BrowserRootView(BrowserView* browser_view,
views::Widget* widget)
: views::internal::RootView(widget),
browser_view_(browser_view),
forwarding_to_tab_strip_(false) { }
bool BrowserRootView::GetDropFormats(
int* formats,
std::set<ui::OSExchangeData::CustomFormat>* custom_formats) {
if (tabstrip() && tabstrip()->visible()) {
*formats = ui::OSExchangeData::URL | ui::OSExchangeData::STRING;
return true;
}
return false;
}
bool BrowserRootView::AreDropTypesRequired() {
return true;
}
bool BrowserRootView::CanDrop(const ui::OSExchangeData& data) {
if (!tabstrip() || !tabstrip()->visible())
return false;
if (data.HasURL(ui::OSExchangeData::CONVERT_FILENAMES))
return true;
return GetPasteAndGoURL(data, NULL);
}
void BrowserRootView::OnDragEntered(const ui::DropTargetEvent& event) {
if (ShouldForwardToTabStrip(event)) {
forwarding_to_tab_strip_ = true;
scoped_ptr<ui::DropTargetEvent> mapped_event(
MapEventToTabStrip(event, event.data()));
tabstrip()->OnDragEntered(*mapped_event.get());
}
}
int BrowserRootView::OnDragUpdated(const ui::DropTargetEvent& event) {
if (ShouldForwardToTabStrip(event)) {
scoped_ptr<ui::DropTargetEvent> mapped_event(
MapEventToTabStrip(event, event.data()));
if (!forwarding_to_tab_strip_) {
tabstrip()->OnDragEntered(*mapped_event.get());
forwarding_to_tab_strip_ = true;
}
return tabstrip()->OnDragUpdated(*mapped_event.get());
} else if (forwarding_to_tab_strip_) {
forwarding_to_tab_strip_ = false;
tabstrip()->OnDragExited();
}
return ui::DragDropTypes::DRAG_NONE;
}
void BrowserRootView::OnDragExited() {
if (forwarding_to_tab_strip_) {
forwarding_to_tab_strip_ = false;
tabstrip()->OnDragExited();
}
}
int BrowserRootView::OnPerformDrop(const ui::DropTargetEvent& event) {
if (!forwarding_to_tab_strip_)
return ui::DragDropTypes::DRAG_NONE;
GURL url;
base::string16 title;
ui::OSExchangeData mapped_data;
if (!event.data().GetURLAndTitle(
ui::OSExchangeData::CONVERT_FILENAMES, &url, &title) ||
!url.is_valid()) {
if (GetPasteAndGoURL(event.data(), &url))
mapped_data.SetURL(url, base::string16());
} else {
mapped_data.SetURL(url, base::string16());
}
forwarding_to_tab_strip_ = false;
scoped_ptr<ui::DropTargetEvent> mapped_event(
MapEventToTabStrip(event, mapped_data));
return tabstrip()->OnPerformDrop(*mapped_event);
}
const char* BrowserRootView::GetClassName() const {
return kViewClassName;
}
bool BrowserRootView::OnMouseWheel(const ui::MouseWheelEvent& event) {
if (browser_defaults::kScrollEventChangesTab) {
views::View* hit_view = GetEventHandlerForPoint(event.location());
views::NonClientView* non_client = GetWidget()->non_client_view();
if (tabstrip()->Contains(hit_view) ||
hit_view == non_client->frame_view()) {
int scroll_offset = abs(event.y_offset()) > abs(event.x_offset()) ?
event.y_offset() : -event.x_offset();
Browser* browser = browser_view_->browser();
TabStripModel* model = browser->tab_strip_model();
if (scroll_offset < 0 && model->active_index() + 1 < model->count()) {
chrome::SelectNextTab(browser);
return true;
}
if (scroll_offset > 0 && model->active_index() > 0) {
chrome::SelectPreviousTab(browser);
return true;
}
}
}
return RootView::OnMouseWheel(event);
}
void BrowserRootView::DispatchGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::ET_GESTURE_TAP &&
event->location().y() <= 0 &&
event->location().x() <= browser_view_->GetBounds().width()) {
TouchUMA::RecordGestureAction(TouchUMA::GESTURE_ROOTVIEWTOP_TAP);
}
RootView::DispatchGestureEvent(event);
}
bool BrowserRootView::ShouldForwardToTabStrip(
const ui::DropTargetEvent& event) {
if (!tabstrip()->visible())
return false;
gfx::Point tab_loc_in_host;
ConvertPointToTarget(tabstrip(), this, &tab_loc_in_host);
return event.y() < tab_loc_in_host.y() + tabstrip()->height();
}
ui::DropTargetEvent* BrowserRootView::MapEventToTabStrip(
const ui::DropTargetEvent& event,
const ui::OSExchangeData& data) {
gfx::Point tab_strip_loc(event.location());
ConvertPointToTarget(this, tabstrip(), &tab_strip_loc);
return new ui::DropTargetEvent(data, tab_strip_loc, tab_strip_loc,
event.source_operations());
}
TabStrip* BrowserRootView::tabstrip() const {
return browser_view_->tabstrip();
}
bool BrowserRootView::GetPasteAndGoURL(const ui::OSExchangeData& data,
GURL* url) {
if (!data.HasString())
return false;
base::string16 text;
if (!data.GetString(&text) || text.empty())
return false;
text = AutocompleteMatch::SanitizeString(text);
AutocompleteMatch match;
AutocompleteClassifierFactory::GetForProfile(
browser_view_->browser()->profile())->Classify(
text, false, false, AutocompleteInput::INVALID_SPEC, &match, NULL);
if (!match.destination_url.is_valid())
return false;
if (url)
*url = match.destination_url;
return true;
}