1
1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
// Copyright (C) 2013-2015 Canonical Ltd.
2
// Copyright (C) 2013-2016 Canonical Ltd.
4
4
// This library is free software; you can redistribute it and/or
5
5
// modify it under the terms of the GNU Lesser General Public
60
60
#include "net/base/net_errors.h"
61
61
#include "net/ssl/ssl_info.h"
62
62
#include "third_party/WebKit/public/web/WebInputEvent.h"
63
#include "ui/base/clipboard/clipboard.h"
63
64
#include "ui/base/window_open_disposition.h"
64
65
#include "ui/events/event.h"
65
66
#include "ui/gl/gl_implementation.h"
66
67
#include "ui/shell_dialogs/selected_file_info.h"
68
#include "ui/touch_selection/touch_selection_controller.h"
67
69
#include "url/gurl.h"
68
70
#include "url/url_constants.h"
149
151
FaviconHelper::CreateForWebContents(contents);
154
bool HasLocationBarOffsetChanged(const cc::CompositorFrameMetadata& old,
155
const cc::CompositorFrameMetadata& current) {
156
if (old.location_bar_offset.y() != current.location_bar_offset.y()) {
159
if (old.location_bar_content_translation.y() !=
160
current.location_bar_content_translation.y()) {
152
166
OXIDE_MAKE_ENUM_BITWISE_OPERATORS(ui::PageTransition)
153
167
OXIDE_MAKE_ENUM_BITWISE_OPERATORS(ContentType)
211
225
location_bar_height_pix_(0),
212
226
location_bar_constraints_(blink::WebTopControlsBoth),
213
227
location_bar_animated_(true),
228
edit_flags_(blink::WebContextMenuData::CanDoNone),
214
229
weak_factory_(this) {
215
230
CHECK(client) << "Didn't specify a client";
435
450
// TODO(chrisccoulson): Merge these
436
451
client_->FrameMetadataUpdated(old);
437
452
client_->SwapCompositorFrame();
454
RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
456
ui::TouchSelectionController* controller = rwhv->selection_controller();
457
// If the location bar offset changes while a touch selection is active,
458
// the bounding rect and the position of the handles need to be updated.
459
if ((controller->active_status() !=
460
ui::TouchSelectionController::INACTIVE) &&
461
HasLocationBarOffsetChanged(old, compositor_frame_metadata_)) {
462
TouchSelectionChanged();
463
// XXX: hack to ensure the position of the handles is updated.
464
controller->SetTemporarilyHidden(true);
465
controller->SetTemporarilyHidden(false);
440
470
void WebView::WebPreferencesDestroyed() {
537
567
active_popup_menu_->Close();
570
ui::TouchHandleDrawable* WebView::CreateTouchHandleDrawable() const {
571
return client_->CreateTouchHandleDrawable();
574
void WebView::TouchSelectionChanged() const {
575
RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
580
ui::TouchSelectionController* controller = rwhv->selection_controller();
582
(controller->active_status() != ui::TouchSelectionController::INACTIVE);
584
gfx::RectF bounds = controller->GetRectBetweenBounds();
585
bounds.Offset(0, GetLocationBarContentOffsetDip());
587
client_->TouchSelectionChanged(active, bounds);
590
void WebView::EditingCapabilitiesChanged() {
591
int flags = blink::WebContextMenuData::CanDoNone;
592
RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
598
ui::TextInputType text_input_type = rwhv->ime_bridge()->text_input_type();
599
bool editable = (text_input_type != ui::TEXT_INPUT_TYPE_NONE);
600
bool readable = (text_input_type != ui::TEXT_INPUT_TYPE_PASSWORD);
601
bool has_selection = !rwhv->selection_range().is_empty();
602
base::string16 clipboard;
603
ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE,
605
// XXX: if editable, can we determine whether undo/redo is available?
606
if (editable && readable && has_selection) {
607
flags |= blink::WebContextMenuData::CanCut;
609
if (readable && has_selection) {
610
flags |= blink::WebContextMenuData::CanCopy;
612
if (editable && !clipboard.empty()) {
613
flags |= blink::WebContextMenuData::CanPaste;
615
if (editable && has_selection) {
616
flags |= blink::WebContextMenuData::CanDelete;
618
flags |= blink::WebContextMenuData::CanSelectAll;
620
if (flags != edit_flags_) {
622
client_->OnEditingCapabilitiesChanged();
540
626
content::WebContents* WebView::OpenURLFromTab(
541
627
content::WebContents* source,
542
628
const content::OpenURLParams& params) {
1190
1278
return handled;
1281
void WebView::ClipboardDataChanged() {
1282
EditingCapabilitiesChanged();
1193
1285
WebView::WebView(const Params& params)
1194
1286
: WebView(params.client) {
1195
1287
CHECK(params.context) << "Didn't specify a BrowserContext";
1676
1768
return gfx::Size(std::round(size.width()), std::round(size.height()));
1679
int WebView::GetLocationBarOffsetPix() {
1771
int WebView::GetLocationBarOffsetPix() const {
1680
1772
return compositor_frame_metadata().location_bar_offset.y() *
1681
1773
compositor_frame_metadata().device_scale_factor;
1684
int WebView::GetLocationBarContentOffsetPix() {
1776
int WebView::GetLocationBarContentOffsetPix() const {
1685
1777
return compositor_frame_metadata().location_bar_content_translation.y() *
1686
1778
compositor_frame_metadata().device_scale_factor;
1689
float WebView::GetLocationBarContentOffsetDip() {
1781
float WebView::GetLocationBarContentOffsetDip() const {
1690
1782
return compositor_frame_metadata().location_bar_content_translation.y();