contents_web_view.cc revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/views/frame/contents_web_view.h" 6 7#include "chrome/browser/themes/theme_properties.h" 8#include "chrome/browser/ui/views/status_bubble_views.h" 9#include "ui/base/theme_provider.h" 10#include "ui/views/background.h" 11 12ContentsWebView::ContentsWebView(content::BrowserContext* browser_context) 13 : views::WebView(browser_context), 14 status_bubble_(NULL) { 15} 16 17ContentsWebView::~ContentsWebView() { 18} 19 20void ContentsWebView::SetStatusBubble(StatusBubbleViews* status_bubble) { 21 status_bubble_ = status_bubble; 22 DCHECK(!status_bubble_ || status_bubble_->base_view() == this); 23 if (status_bubble_) 24 status_bubble_->Reposition(); 25} 26 27bool ContentsWebView::NeedsNotificationWhenVisibleBoundsChange() const { 28 return true; 29} 30 31void ContentsWebView::OnVisibleBoundsChanged() { 32 if (status_bubble_) 33 status_bubble_->Reposition(); 34} 35 36void ContentsWebView::ViewHierarchyChanged( 37 const ViewHierarchyChangedDetails& details) { 38 WebView::ViewHierarchyChanged(details); 39 if (details.is_add) 40 OnThemeChanged(); 41} 42 43void ContentsWebView::OnThemeChanged() { 44 ui::ThemeProvider* const theme = GetThemeProvider(); 45 if (!theme) 46 return; 47 48 // Set the background color to a dark tint of the new tab page's background 49 // color. This is the color filled within the WebView's bounds when its child 50 // view is sized specially for fullscreen tab capture. See WebView header 51 // file comments for more details. 52 const int kBackgroundBrightness = 0x33; // 20% 53 const SkColor ntp_background = 54 theme->GetColor(ThemeProperties::COLOR_NTP_BACKGROUND); 55 set_background(views::Background::CreateSolidBackground( 56 SkColorGetR(ntp_background) * kBackgroundBrightness / 0xFF, 57 SkColorGetG(ntp_background) * kBackgroundBrightness / 0xFF, 58 SkColorGetB(ntp_background) * kBackgroundBrightness / 0xFF, 59 SkColorGetA(ntp_background))); 60} 61