~osomon/oxide/override-touchUngrabEvent

« back to all changes in this revision

Viewing changes to shared/browser/oxide_web_view.cc

  • Committer: Olivier Tilloy
  • Date: 2016-01-12 11:46:34 UTC
  • mfrom: (1272.2.38 touch-selection-api)
  • Revision ID: olivier.tilloy@canonical.com-20160112114634-u1t78baa0u4hfoha
Add a touch selection API, to allow embedders to display handles for resizing the current selection, and contextual actions for it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
 
// Copyright (C) 2013-2015 Canonical Ltd.
 
2
// Copyright (C) 2013-2016 Canonical Ltd.
3
3
 
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"
69
71
 
149
151
  FaviconHelper::CreateForWebContents(contents);
150
152
}
151
153
 
 
154
bool HasLocationBarOffsetChanged(const cc::CompositorFrameMetadata& old,
 
155
                                 const cc::CompositorFrameMetadata& current) {
 
156
  if (old.location_bar_offset.y() != current.location_bar_offset.y()) {
 
157
    return true;
 
158
  }
 
159
  if (old.location_bar_content_translation.y() !=
 
160
      current.location_bar_content_translation.y()) {
 
161
    return true;
 
162
  }
 
163
  return false;
 
164
}
 
165
 
152
166
OXIDE_MAKE_ENUM_BITWISE_OPERATORS(ui::PageTransition)
153
167
OXIDE_MAKE_ENUM_BITWISE_OPERATORS(ContentType)
154
168
 
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";
216
231
 
435
450
  // TODO(chrisccoulson): Merge these
436
451
  client_->FrameMetadataUpdated(old);
437
452
  client_->SwapCompositorFrame();
 
453
 
 
454
  RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
 
455
  if (rwhv) {
 
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);
 
466
    }
 
467
  }
438
468
}
439
469
 
440
470
void WebView::WebPreferencesDestroyed() {
537
567
  active_popup_menu_->Close();
538
568
}
539
569
 
 
570
ui::TouchHandleDrawable* WebView::CreateTouchHandleDrawable() const {
 
571
  return client_->CreateTouchHandleDrawable();
 
572
}
 
573
 
 
574
void WebView::TouchSelectionChanged() const {
 
575
  RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
 
576
  if (!rwhv) {
 
577
    return;
 
578
  }
 
579
 
 
580
  ui::TouchSelectionController* controller = rwhv->selection_controller();
 
581
  bool active =
 
582
      (controller->active_status() != ui::TouchSelectionController::INACTIVE);
 
583
 
 
584
  gfx::RectF bounds = controller->GetRectBetweenBounds();
 
585
  bounds.Offset(0, GetLocationBarContentOffsetDip());
 
586
 
 
587
  client_->TouchSelectionChanged(active, bounds);
 
588
}
 
589
 
 
590
void WebView::EditingCapabilitiesChanged() {
 
591
  int flags = blink::WebContextMenuData::CanDoNone;
 
592
  RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
 
593
  if (!rwhv) {
 
594
    edit_flags_ = flags;
 
595
    return;
 
596
  }
 
597
 
 
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,
 
604
                                                 &clipboard);
 
605
  // XXX: if editable, can we determine whether undo/redo is available?
 
606
  if (editable && readable && has_selection) {
 
607
    flags |= blink::WebContextMenuData::CanCut;
 
608
  }
 
609
  if (readable && has_selection) {
 
610
    flags |= blink::WebContextMenuData::CanCopy;
 
611
  }
 
612
  if (editable && !clipboard.empty()) {
 
613
    flags |= blink::WebContextMenuData::CanPaste;
 
614
  }
 
615
  if (editable && has_selection) {
 
616
    flags |= blink::WebContextMenuData::CanDelete;
 
617
  }
 
618
  flags |= blink::WebContextMenuData::CanSelectAll;
 
619
  
 
620
  if (flags != edit_flags_) {
 
621
    edit_flags_ = flags;
 
622
    client_->OnEditingCapabilitiesChanged();
 
623
  }
 
624
}
 
625
 
540
626
content::WebContents* WebView::OpenURLFromTab(
541
627
    content::WebContents* source,
542
628
    const content::OpenURLParams& params) {
971
1057
  }
972
1058
 
973
1059
  InitializeTopControlsForHost(new_host, !old_host);
 
1060
 
 
1061
  EditingCapabilitiesChanged();
974
1062
}
975
1063
 
976
1064
void WebView::DidStartLoading() {
1190
1278
  return handled;
1191
1279
}
1192
1280
 
 
1281
void WebView::ClipboardDataChanged() {
 
1282
  EditingCapabilitiesChanged();
 
1283
}
 
1284
 
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()));
1677
1769
}
1678
1770
 
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;
1682
1774
}
1683
1775
 
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;
1687
1779
}
1688
1780
 
1689
 
float WebView::GetLocationBarContentOffsetDip() {
 
1781
float WebView::GetLocationBarContentOffsetDip() const {
1690
1782
  return compositor_frame_metadata().location_bar_content_translation.y();
1691
1783
}
1692
1784
 
1958
2050
  return client_->CanCreateWindows();
1959
2051
}
1960
2052
 
 
2053
int WebView::GetEditFlags() const {
 
2054
  return edit_flags_;
 
2055
}
 
2056
 
1961
2057
} // namespace oxide
1962
2058