Commit message: None
CVE: None
Vulnerability description: None

Project: Chrome

scoped_ptr<EdgeEffectBase> OverscrollControllerAndroid::CreateEdgeEffect() {
  return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_);
}

Project: Chrome

scoped_ptr<EdgeEffectBase> CreateGlowEdgeEffect(
    ui::ResourceManager* resource_manager,
    float dpi_scale) {
  DCHECK(resource_manager);
  if (IsAndroidLOrNewer())
    return scoped_ptr<EdgeEffectBase>(new EdgeEffectL(resource_manager));

  return scoped_ptr<EdgeEffectBase>(
      new EdgeEffect(resource_manager, dpi_scale));
}

Project: Chrome

scoped_ptr<OverscrollGlow> CreateGlowEffect(OverscrollGlowClient* client,
                                            float dpi_scale) {
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          switches::kDisableOverscrollEdgeEffect)) {
    return nullptr;
  }

  return make_scoped_ptr(new OverscrollGlow(client));
}

Project: Chrome

scoped_ptr<OverscrollRefresh> CreateRefreshEffect(
    OverscrollRefreshHandler* handler) {
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          switches::kDisablePullToRefreshEffect)) {
    return nullptr;
  }

  return make_scoped_ptr(new OverscrollRefresh(handler));
}

Project: Chrome

void OverscrollControllerAndroid::Disable() {
  if (!enabled_)
    return;
  enabled_ = false;
  if (!enabled_) {
    if (refresh_effect_)
      refresh_effect_->Reset();
    if (glow_effect_)
      glow_effect_->Reset();
  }
}

Project: Chrome

void OverscrollControllerAndroid::Enable() {
  enabled_ = true;
}

Project: Chrome

float MinGlowAlphaToDisableRefresh() {
  if (IsAndroidLOrNewer())
    return kMinGlowAlphaToDisableRefreshOnL;

  return 1.01f;
}

Project: Chrome

void OverscrollControllerAndroid::OnFrameMetadataUpdated(
    const cc::CompositorFrameMetadata& frame_metadata) {
  if (!refresh_effect_ && !glow_effect_)
    return;

  const float scale_factor =
      frame_metadata.page_scale_factor * frame_metadata.device_scale_factor;
  gfx::SizeF viewport_size =
      gfx::ScaleSize(frame_metadata.scrollable_viewport_size, scale_factor);
  gfx::SizeF content_size =
      gfx::ScaleSize(frame_metadata.root_layer_size, scale_factor);
  gfx::Vector2dF content_scroll_offset =
      gfx::ScaleVector2d(frame_metadata.root_scroll_offset, scale_factor);

  if (refresh_effect_) {
    refresh_effect_->OnFrameUpdated(content_scroll_offset,
                                    frame_metadata.root_overflow_y_hidden);
  }

  if (glow_effect_) {
    glow_effect_->OnFrameUpdated(viewport_size, content_size,
                                 content_scroll_offset);
  }
}

Project: Chrome

void OverscrollControllerAndroid::OnGestureEventAck(
    const blink::WebGestureEvent& event,
    InputEventAckState ack_result) {
  if (!enabled_)
    return;

  if (event.type == blink::WebInputEvent::GestureScrollEnd ||
      event.type == blink::WebInputEvent::GestureFlingStart) {
    OnOverscrolled(DidOverscrollParams());
  }

  if (event.type == blink::WebInputEvent::GestureScrollUpdate &&
      refresh_effect_) {
    bool consumed = ack_result == INPUT_EVENT_ACK_STATE_CONSUMED ||
                    event.data.scrollUpdate.previousUpdateInSequencePrevented;
    refresh_effect_->OnScrollUpdateAck(consumed);
  }
}

Project: Chrome

void OverscrollControllerAndroid::OnOverscrolled(
    const DidOverscrollParams& params) {
  if (!enabled_)
    return;

  if (refresh_effect_ && (refresh_effect_->IsActive() ||
                          refresh_effect_->IsAwaitingScrollUpdateAck())) {
    return;
  }

  if (glow_effect_ &&
      glow_effect_->OnOverscrolled(
          base::TimeTicks::Now(),
          gfx::ScaleVector2d(params.accumulated_overscroll, dpi_scale_),
          gfx::ScaleVector2d(params.latest_overscroll_delta, dpi_scale_),
          gfx::ScaleVector2d(params.current_fling_velocity, dpi_scale_),
          gfx::ScaleVector2d(
              params.causal_event_viewport_point.OffsetFromOrigin(),
              dpi_scale_))) {
    SetNeedsAnimate();
  }
}

Project: Chrome

OverscrollControllerAndroid::OverscrollControllerAndroid(
    ContentViewCoreImpl* content_view_core)
    : compositor_(content_view_core->GetWindowAndroid()->GetCompositor()),
      dpi_scale_(content_view_core->GetDpiScale()),
      enabled_(true),
      glow_effect_(CreateGlowEffect(this, dpi_scale_)),
      refresh_effect_(CreateRefreshEffect(content_view_core)),
      is_fullscreen_(false) {
  DCHECK(compositor_);
  if (refresh_effect_) {
    WebContentsImpl* web_contents =
        static_cast<WebContentsImpl*>(content_view_core->GetWebContents());
    is_fullscreen_ = web_contents->IsFullscreenForCurrentTab();
    Observe(web_contents);
  }
}

Project: Chrome

bool OverscrollControllerAndroid::WillHandleGestureEvent(
    const blink::WebGestureEvent& event) {
  if (!enabled_)
    return false;

  if (!refresh_effect_)
    return false;

  if (is_fullscreen_)
    return false;

  if (glow_effect_ && glow_effect_->IsActive()) {
    if (glow_effect_->GetVisibleAlpha() > MinGlowAlphaToDisableRefresh())
      return false;
  }

  bool handled = false;
  switch (event.type) {
    case blink::WebInputEvent::GestureScrollBegin:
      refresh_effect_->OnScrollBegin();
      break;

    case blink::WebInputEvent::GestureScrollUpdate: {
      gfx::Vector2dF scroll_delta(event.data.scrollUpdate.deltaX,
                                  event.data.scrollUpdate.deltaY);
      scroll_delta.Scale(dpi_scale_);
      handled = refresh_effect_->WillHandleScrollUpdate(scroll_delta);
    } break;

    case blink::WebInputEvent::GestureScrollEnd:
      refresh_effect_->OnScrollEnd(gfx::Vector2dF());
      break;

    case blink::WebInputEvent::GestureFlingStart: {
      if (refresh_effect_->IsActive()) {
        gfx::Vector2dF scroll_velocity(event.data.flingStart.velocityX,
                                       event.data.flingStart.velocityY);
        scroll_velocity.Scale(dpi_scale_);
        refresh_effect_->OnScrollEnd(scroll_velocity);
        blink::WebGestureEvent& modified_event =
            const_cast<blink::WebGestureEvent&>(event);
        modified_event.data.flingStart.velocityX = .01f;
        modified_event.data.flingStart.velocityY = .01f;
      }
    } break;

    case blink::WebInputEvent::GesturePinchBegin:
      refresh_effect_->ReleaseWithoutActivation();
      break;

    default:
      break;
  }

  return handled;
}

Project: Chrome

OverscrollControllerAndroid::~OverscrollControllerAndroid() {
}