Commit 502356d4 authored by sadrul@chromium.org's avatar sadrul@chromium.org

Integrate WebUI Login with cros.

This patch covers integrating the the WebUI based login with cros, so that when --dom-login is passed in on boot the WebUI login screen is used, keyboard comes up and the user can login.

I have refactored the WebUI login code to not use a subclass of the Browser class. I have removed the unneeded DOMBrowser* classes. This work was based off a combination of the BackgroundView and the TouchBrowserFrameView. If there is comments or variable names that betray this please let me know. I have endevoured to update the comments, but significant portions of code were pulled in.

Since both of the TouchBrowserFrameView and WebUILoginView have common code for having a a touch keyboard there is some refactoring to be done that will remove duplicated code between the two. This will be dealt with in a follow on CL.

The animation of the keyboard has not been included in this CL, mostly because I was having issues getting it to correctly size and this CL is pretty large already. This will be resolved in a follow on CL.

I am also converting from the use of DOM to WebUI at the moment, so some of the new code uses WebUI instead of DOM. I will be uploading a follow on CL that finishes this conversion.

This CL depends on http://gerrit.chromium.org/gerrit/706 and http://gerrit.chromium.org/gerrit/759 landing before it to work correctly.

It also depends on http://codereview.chromium.org/7014021/ to build.

Patch from Ryan Harrison <rharrison@chromium.org>

BUG=none
TEST=manual

Review URL: http://codereview.chromium.org/6973029
Patch from Ryan Harrison <rharrison@chromium.org>.

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86659 0039d316-1c4b-4281-b951-d872f2087c98
parent fc172d24
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/frame/dom_browser.h"
#include "chrome/browser/chromeos/frame/dom_browser_view.h"
#include "chrome/browser/ui/browser_window.h"
namespace chromeos {
// DOMBrowser: public ----------------------------------------------------------
DOMBrowser::DOMBrowser(Profile* profile)
: Browser(Browser::TYPE_TABBED, profile) {
}
DOMBrowser::~DOMBrowser() {
}
// static
DOMBrowser* DOMBrowser::CreateForDOM(Profile* profile) {
DOMBrowser* browser = new DOMBrowser(profile);
browser->InitBrowserWindow();
return browser;
}
BrowserWindow* DOMBrowser::CreateBrowserWindow() {
return DOMBrowserView::CreateDOMWindow(this);
}
} // namespace chromeos
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_FRAME_DOM_BROWSER_H_
#define CHROME_BROWSER_CHROMEOS_FRAME_DOM_BROWSER_H_
#pragma once
#include "base/basictypes.h"
#include "chrome/browser/ui/browser.h"
class Profile;
namespace chromeos {
// DOMBrowser is an alternate implementation of Browser that is used to display
// DOM login screens. These screens in addition to having a webpage in a DOMView
// also display the Status Area and the touch enabled keyboard.
// TODO(rharrison): Add support for OOBE and screen lock DOM screens.
class DOMBrowser : public Browser {
public:
explicit DOMBrowser(Profile* profile);
virtual ~DOMBrowser();
// This is a factory method for creating a DOMBrowser. It is based off of the
// CreateFor* methods from the Browser class.
static DOMBrowser* CreateForDOM(Profile* profile);
protected:
// Creates Window for DOMBrowser.
virtual BrowserWindow* CreateBrowserWindow();
private:
DISALLOW_COPY_AND_ASSIGN(DOMBrowser);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_FRAME_DOM_BROWSER_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/frame/dom_browser_view.h"
#include "chrome/browser/chromeos/frame/dom_browser_view_layout.h"
#include "ui/gfx/rect.h"
#include "views/widget/widget.h"
namespace chromeos {
// DOMBrowserView, public ------------------------------------------------------
DOMBrowserView::DOMBrowserView(Browser* browser)
: chromeos::BrowserView(browser) {}
DOMBrowserView::~DOMBrowserView() {}
// static
BrowserWindow* DOMBrowserView::CreateDOMWindow(Browser* browser) {
DOMBrowserView* view = new DOMBrowserView(browser);
(new BrowserFrame(view))->InitBrowserFrame();
return view;
}
void DOMBrowserView::WindowMoveOrResizeStarted() {}
gfx::Rect DOMBrowserView::GetToolbarBounds() const {
return gfx::Rect();
}
int DOMBrowserView::GetTabStripHeight() const {
return 0;
}
bool DOMBrowserView::IsTabStripVisible() const {
return false;
}
bool DOMBrowserView::AcceleratorPressed(const views::Accelerator& accelerator) {
return false;
}
void DOMBrowserView::SetStarredState(bool is_starred) {}
LocationBar* DOMBrowserView::GetLocationBar() const {
return NULL;
}
void DOMBrowserView::SetFocusToLocationBar(bool select_all) {}
void DOMBrowserView::UpdateReloadStopState(bool is_loading, bool force) {}
void DOMBrowserView::UpdateToolbar(TabContentsWrapper* contents,
bool should_restore_state) {}
void DOMBrowserView::FocusToolbar() {}
void DOMBrowserView::FocusAppMenu() {}
void DOMBrowserView::ShowBookmarkBubble(const GURL& url,
bool already_bookmarked) {}
void DOMBrowserView::ShowAppMenu() {}
LocationBarView* DOMBrowserView::GetLocationBarView() const {
return NULL;
}
ToolbarView* DOMBrowserView::GetToolbarView() const {
return NULL;
}
bool DOMBrowserView::ShouldShowOffTheRecordAvatar() const {
return false;
}
bool DOMBrowserView::GetAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator) {
return GetWidget()->GetAccelerator(command_id, accelerator);
}
bool DOMBrowserView::IsToolbarVisible() const {
return false;
}
// DOMBrowserView, protected ---------------------------------------------------
void DOMBrowserView::GetAccessiblePanes(
std::vector<AccessiblePaneView*>* panes) {}
void DOMBrowserView::PaintChildren(gfx::Canvas* canvas) {
views::ClientView::PaintChildren(canvas);
}
void DOMBrowserView::InitTabStrip(TabStripModel* model) {}
views::LayoutManager* DOMBrowserView::CreateLayoutManager() const {
return new DOMBrowserViewLayout;
}
ToolbarView* DOMBrowserView::CreateToolbar() const {
return NULL;
}
void DOMBrowserView::LoadingAnimationCallback() {}
} // namespace chromeos
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_FRAME_DOM_BROWSER_VIEW_H_
#define CHROME_BROWSER_CHROMEOS_FRAME_DOM_BROWSER_VIEW_H_
#pragma once
#include <vector>
#include "base/compiler_specific.h"
#include "chrome/browser/chromeos/frame/browser_view.h"
namespace chromeos {
// DOMBrowserView overides a large number of methods that are defined in
// chromeos::BrowserView and BrowserView to resolve issues with UX components
// like the Tabstrip and Location Bar being removed. It also overides the
// construction functions required to create these UX elements.
class DOMBrowserView : public chromeos::BrowserView {
public:
explicit DOMBrowserView(Browser* browser);
virtual ~DOMBrowserView();
// Create a DOMBrowserView for a DOMBrowser.
static BrowserWindow* CreateDOMWindow(Browser* browser);
// BrowserView overrides
virtual void WindowMoveOrResizeStarted() OVERRIDE;
virtual gfx::Rect GetToolbarBounds() const OVERRIDE;
virtual int GetTabStripHeight() const OVERRIDE;
virtual bool IsTabStripVisible() const OVERRIDE;
virtual bool AcceleratorPressed(const views::Accelerator& accelerator)
OVERRIDE;
virtual void SetStarredState(bool is_starred) OVERRIDE;
virtual LocationBar* GetLocationBar() const OVERRIDE;
virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
virtual void UpdateReloadStopState(bool is_loading, bool force) OVERRIDE;
virtual void UpdateToolbar(TabContentsWrapper* contents,
bool should_restore_state) OVERRIDE;
virtual void FocusToolbar() OVERRIDE;
virtual void FocusAppMenu() OVERRIDE;
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked)
OVERRIDE;
virtual void ShowAppMenu() OVERRIDE;
virtual LocationBarView* GetLocationBarView() const OVERRIDE;
virtual ToolbarView* GetToolbarView() const OVERRIDE;
virtual bool ShouldShowOffTheRecordAvatar() const OVERRIDE;
virtual bool GetAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator)
OVERRIDE;
// BrowserWindow overrides
bool IsToolbarVisible() const OVERRIDE;
protected:
// BrowserView overrides
virtual void GetAccessiblePanes(
std::vector<AccessiblePaneView*>* panes) OVERRIDE;
virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
virtual void InitTabStrip(TabStripModel* model) OVERRIDE;
virtual views::LayoutManager* CreateLayoutManager() const OVERRIDE;
virtual ToolbarView* CreateToolbar() const OVERRIDE;
virtual void LoadingAnimationCallback() OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(DOMBrowserView);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_FRAME_DOM_BROWSER_VIEW_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/frame/dom_browser_view_layout.h"
#include <algorithm>
#include "chrome/browser/chromeos/status/status_area_view.h"
#include "chrome/browser/chromeos/view_ids.h"
#include "views/window/hit_test.h"
namespace chromeos {
// DOMBrowserViewLayout public: ------------------------------------------------
DOMBrowserViewLayout::DOMBrowserViewLayout() : ::BrowserViewLayout() {}
DOMBrowserViewLayout::~DOMBrowserViewLayout() {}
// DOMBrowserViewLayout, ::DOMBrowserViewLayout overrides: ---------------------
void DOMBrowserViewLayout::Installed(views::View* host) {
status_area_ = NULL;
::BrowserViewLayout::Installed(host);
}
void DOMBrowserViewLayout::ViewAdded(views::View* host,
views::View* view) {
::BrowserViewLayout::ViewAdded(host, view);
switch (view->GetID()) {
case VIEW_ID_STATUS_AREA:
status_area_ = static_cast<chromeos::StatusAreaView*>(view);
break;
}
}
int DOMBrowserViewLayout::LayoutTabStrip() {
status_area_->SetVisible(true);
gfx::Size status_size = status_area_->GetPreferredSize();
status_area_->SetBounds(vertical_layout_rect_.width() - status_size.width(),
0,
vertical_layout_rect_.width(),
status_size.height());
return status_size.height();
}
int DOMBrowserViewLayout::LayoutToolbar(int top) {
return top;
}
int DOMBrowserViewLayout::LayoutBookmarkAndInfoBars(int top) {
return top;
}
bool DOMBrowserViewLayout::IsPositionInWindowCaption(const gfx::Point& point) {
return false;
}
int DOMBrowserViewLayout::NonClientHitTest(const gfx::Point& point) {
views::View* parent = browser_view_->parent();
gfx::Point point_in_browser_view_coords(point);
views::View::ConvertPointToView(
parent, browser_view_, &point_in_browser_view_coords);
gfx::Rect bv_bounds = browser_view_->bounds();
if (bv_bounds.Contains(point))
return HTCLIENT;
// If the point is somewhere else, delegate to the default implementation.
return browser_view_->views::ClientView::NonClientHitTest(point);
}
// DOMBrowserViewLayout private: -----------------------------------------------
bool DOMBrowserViewLayout::IsPointInViewsInTitleArea(const gfx::Point& point)
const {
gfx::Point point_in_status_area_coords(point);
views::View::ConvertPointToView(browser_view_, status_area_,
&point_in_status_area_coords);
return status_area_->HitTest(point_in_status_area_coords);
}
int DOMBrowserViewLayout::LayoutTitlebarComponents(const gfx::Rect& bounds) {
status_area_->SetVisible(true);
gfx::Size status_size = status_area_->GetPreferredSize();
status_area_->SetBounds(bounds.right() - status_size.width(),
bounds.y(),
status_size.width(),
status_size.height());
return status_size.height();
}
const DOMBrowserView* DOMBrowserViewLayout::GetDOMBrowserView() {
return static_cast<DOMBrowserView*>(browser_view_);
}
} // namespace chromeos
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_FRAME_DOM_BROWSER_VIEW_LAYOUT_H_
#define CHROME_BROWSER_CHROMEOS_FRAME_DOM_BROWSER_VIEW_LAYOUT_H_
#pragma once
#include "base/compiler_specific.h"
#include "chrome/browser/chromeos/frame/dom_browser_view.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
#include "chrome/browser/ui/views/frame/browser_view_layout.h"
namespace chromeos {
class DOMBrowserView;
class StatusAreaView;
// LayoutManager for DOMBrowserView, which lays out the StatusAreaView in the
// top corner and ommits the other elements that have been removed from the
// view. There is a bar accross the top of the screen which is clearly divided
// from the rest of the screen. The far left side will eventually have Add User
// button in it.
//
// |-------------------------------------------------------|
// |[ Future Add User button] [Status Area View]| <-- DOMBrowserView
// |-------------------------------------------------------|
// | |
// | |
// | DOM screen |
// | |
// | |
// | |
// |-------------------------------------------------------|
// | |
// | |
// | Touch Keyboard |
// | |
// | |
// |-------------------------------------------------------|
class DOMBrowserViewLayout : public ::BrowserViewLayout {
public:
DOMBrowserViewLayout();
virtual ~DOMBrowserViewLayout();
// BrowserViewLayout overrides:
virtual void Installed(views::View* host) OVERRIDE;
virtual void ViewAdded(views::View* host,
views::View* view) OVERRIDE;
virtual bool IsPositionInWindowCaption(const gfx::Point& point) OVERRIDE;
virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
protected:
// BrowserViewLayout overrides:
virtual int LayoutTabStrip() OVERRIDE;
virtual int LayoutToolbar(int top) OVERRIDE;
virtual int LayoutBookmarkAndInfoBars(int top) OVERRIDE;
private:
const DOMBrowserView* GetDOMBrowserView();
StatusAreaView* status_area_;
// Tests if the point is on one of views that are within the
// considered title bar area of client view.
bool IsPointInViewsInTitleArea(const gfx::Point& point) const;
// Lays out tabstrip and status area in the title bar area (given by
// |bounds|).
int LayoutTitlebarComponents(const gfx::Rect& bounds);
DISALLOW_COPY_AND_ASSIGN(DOMBrowserViewLayout);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_FRAME_DOM_BROWSER_VIEW_LAYOUT_H_
......@@ -42,11 +42,6 @@
#include "views/screen.h"
#include "views/window/window.h"
// X Windows headers have "#define Status int". That interferes with
// NetworkLibrary header which defines enum "Status".
#include <X11/cursorfont.h> // NOLINT
#include <X11/Xcursor/Xcursor.h> // NOLINT
using views::Widget;
namespace {
......@@ -72,17 +67,6 @@ int GetStepId(size_t step) {
}
}
// This gets rid of the ugly X default cursor.
static void ResetXCursor() {
// TODO(sky): nuke this once new window manager is in place.
Display* display = ui::GetXDisplay();
Cursor cursor = XCreateFontCursor(display, XC_left_ptr);
XID root_window = ui::GetX11RootWindow();
XSetWindowAttributes attr;
attr.cursor = cursor;
XChangeWindowAttributes(display, root_window, CWCursor, &attr);
}
} // namespace
namespace chromeos {
......@@ -96,7 +80,6 @@ BackgroundView::BackgroundView()
boot_times_label_(NULL),
progress_bar_(NULL),
shutdown_button_(NULL),
did_paint_(false),
#if defined(OFFICIAL_BUILD)
is_official_build_(true),
#else
......@@ -143,8 +126,6 @@ views::Widget* BackgroundView::CreateWindowContainingView(
const gfx::Rect& bounds,
const GURL& background_url,
BackgroundView** view) {
ResetXCursor();
Widget* window = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
params.bounds = bounds;
......@@ -228,14 +209,6 @@ bool BackgroundView::ScreenSaverEnabled() {
///////////////////////////////////////////////////////////////////////////////
// BackgroundView protected:
void BackgroundView::OnPaint(gfx::Canvas* canvas) {
views::View::OnPaint(canvas);
if (!did_paint_) {
did_paint_ = true;
UpdateWindowType();
}
}
void BackgroundView::Layout() {
const int kCornerPadding = 5;
const int kInfoLeftPadding = 10;
......@@ -416,7 +389,6 @@ void BackgroundView::InitProgressBar() {
void BackgroundView::UpdateWindowType() {
std::vector<int> params;
params.push_back(did_paint_ ? 1 : 0);
WmIpc::instance()->SetWindowType(
GTK_WIDGET(GetNativeWindow()),
WM_IPC_WINDOW_LOGIN_BACKGROUND,
......
......@@ -103,7 +103,6 @@ class BackgroundView : public views::View,
protected:
// Overridden from views::View:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void Layout() OVERRIDE;
virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
virtual void OnLocaleChanged() OVERRIDE;
......@@ -170,11 +169,6 @@ class BackgroundView : public views::View,
// Used to request the boot times.
CancelableRequestConsumer boot_times_consumer_;
// Has Paint been invoked once? The value of this is passed to the window
// manager.
// TODO(sky): nuke this when the wm knows when chrome has painted.
bool did_paint_;
// True if running official BUILD.
bool is_official_build_;
......
......@@ -4,10 +4,10 @@
#include "chrome/browser/chromeos/login/dom_login_display.h"
#include "chrome/browser/chromeos/frame/dom_browser.h"
#include "chrome/browser/chromeos/wm_ipc.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_window.h"
#include "views/widget/widget.h"
namespace {
const char kLoginURL[] = "chrome://login";
......@@ -18,8 +18,8 @@ namespace chromeos {
// DOMLoginDisplay, public: ---------------------------------------------------
DOMLoginDisplay::~DOMLoginDisplay() {
if (login_screen_)
login_screen_->CloseWindow();
if (webui_login_window_)
webui_login_window_->Close();
}
// DOMLoginDisplay, Singleton implementation: ----------------------------------
......@@ -31,9 +31,24 @@ DOMLoginDisplay* DOMLoginDisplay::GetInstance() {
// LoginDisplay implementation: ------------------------------------------------
// static
views::Widget* DOMLoginDisplay::GetLoginWindow() {
return DOMLoginDisplay::GetInstance()->LoginWindow();
}
views::Widget* DOMLoginDisplay::LoginWindow() {
return webui_login_window_;
}
void DOMLoginDisplay::Destroy() {
background_bounds_ = gfx::Rect();
delegate_ = NULL;
if (webui_login_window_)
webui_login_window_->Close();
webui_login_window_ = NULL;
webui_login_view_ = NULL;
}
void DOMLoginDisplay::Init(const std::vector<UserManager::User>& users,
......@@ -45,10 +60,11 @@ void DOMLoginDisplay::Init(const std::vector<UserManager::User>& users,
// TODO(rharrison): Add mechanism to pass in the show_guest and show_new_user
// values.
login_screen_ = DOMBrowser::CreateForDOM(ProfileManager::GetDefaultProfile());
login_screen_->AddSelectedTabWithURL(GURL(kLoginURL),
PageTransition::START_PAGE);
login_screen_->window()->Show();
webui_login_window_ = WebUILoginView::CreateWindowContainingView(
background_bounds_,
GURL(kLoginURL),
&webui_login_view_);
webui_login_window_->Show();
}
void DOMLoginDisplay::OnBeforeUserRemoved(const std::string& username) {
......@@ -104,6 +120,8 @@ void DOMLoginDisplay::LoginAsGuest() {
DOMLoginDisplay::DOMLoginDisplay()
: LoginDisplay(NULL, gfx::Rect()),
LoginUIHandlerDelegate(),
login_screen_(NULL) {}
webui_login_view_(NULL),
webui_login_window_(NULL) {
}
} // namespace chromeos
......@@ -12,6 +12,7 @@
#include "base/scoped_ptr.h"
#include "chrome/browser/chromeos/login/login_display.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/webui_login_view.h"
#include "chrome/browser/ui/webui/chromeos/login/login_ui.h"
namespace gfx {
......@@ -48,6 +49,12 @@ class DOMLoginDisplay : public LoginDisplay,
// Singleton implementation:
static DOMLoginDisplay* GetInstance();
// Wrapper used to help in routing keyboard key presses into the login
// screen. This gets the Login Window widget from the Singleton, so that other
// classes don't need to know we are a Singleton
static views::Widget* GetLoginWindow();
views::Widget* LoginWindow();
// LoginDisplay implementation:
virtual void Destroy() OVERRIDE;
virtual void Init(const std::vector<UserManager::User>& users,
......@@ -76,7 +83,8 @@ class DOMLoginDisplay : public LoginDisplay,
std::vector<UserManager::User> users_;
// Container of the screen we are displaying
DOMBrowser* login_screen_;
WebUILoginView* webui_login_view_; // Owned by webui_login_window_
views::Widget* webui_login_window_;
DISALLOW_COPY_AND_ASSIGN(DOMLoginDisplay);
};
......
......@@ -11,9 +11,11 @@ namespace chromeos {
// DOMLoginDisplayHost -------------------------------------------------------
DOMLoginDisplayHost::DOMLoginDisplayHost(const gfx::Rect& background_bounds)
: BaseLoginDisplayHost(background_bounds) {}
: BaseLoginDisplayHost(background_bounds) {
}
DOMLoginDisplayHost::~DOMLoginDisplayHost() {}
DOMLoginDisplayHost::~DOMLoginDisplayHost() {
}
// LoginDisplayHost implementation -----------------------------------------
......@@ -29,17 +31,23 @@ gfx::NativeWindow DOMLoginDisplayHost::GetNativeWindow() const {
return NULL;
}
void DOMLoginDisplayHost::SetOobeProgress(BackgroundView::LoginStep step) {}
void DOMLoginDisplayHost::SetOobeProgress(BackgroundView::LoginStep step) {
}
void DOMLoginDisplayHost::SetOobeProgressBarVisible(bool visible) {}
void DOMLoginDisplayHost::SetOobeProgressBarVisible(bool visible) {
}
void DOMLoginDisplayHost::SetShutdownButtonEnabled(bool enable) {}
void DOMLoginDisplayHost::SetShutdownButtonEnabled(bool enable) {
}
void DOMLoginDisplayHost::SetStatusAreaEnabled(bool enable) {}
void DOMLoginDisplayHost::SetStatusAreaEnabled(bool enable) {
}
void DOMLoginDisplayHost::SetStatusAreaVisible(bool visible) {}
void DOMLoginDisplayHost::SetStatusAreaVisible(bool visible) {
}
void DOMLoginDisplayHost::ShowBackground() {}
void DOMLoginDisplayHost::ShowBackground() {
}
} // namespace chromeos
......@@ -9,7 +9,6 @@
#include <string>
#include "chrome/browser/chromeos/login/base_login_display_host.h"
#include "ui/gfx/rect.h"
namespace gfx {
class Rect;
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/webui_login_view.h"
#include <vector>
#include "base/logging.h"
#include "chrome/browser/chromeos/login/login_utils.h"
#include "chrome/browser/chromeos/login/proxy_settings_dialog.h"
#include "chrome/browser/chromeos/status/clock_menu_button.h"
#include "chrome/browser/chromeos/status/input_method_menu_button.h"
#include "chrome/browser/chromeos/status/network_menu_button.h"
#include "chrome/browser/chromeos/status/status_area_view.h"
#include "chrome/browser/chromeos/wm_ipc.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
#include "chrome/browser/ui/touch/frame/keyboard_container_view.h"
#include "chrome/browser/ui/views/dom_view.h"
#include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/common/notification_service.h"
#include "googleurl/src/gurl.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/transform.h"
#include "views/controls/textfield/textfield.h"
#include "views/widget/widget.h"
// TODO(rharrison): Modify this class to support both touch and non-touch
namespace {
const int kKeyboardHeight = 300;
const int kKeyboardSlideDuration = 500; // In milliseconds
PropertyAccessor<bool>* GetFocusedStateAccessor() {
static PropertyAccessor<bool> state;
return &state;
}
bool TabContentsHasFocus(const TabContents* contents) {
views::View* view = static_cast<TabContentsViewTouch*>(contents->view());
return view->Contains(view->GetFocusManager()->GetFocusedView());
}
} // namespace
namespace chromeos {
// static
const char WebUILoginView::kViewClassName[] =
"browser/chromeos/login/WebUILoginView";
// WebUILoginView public: ------------------------------------------------------
WebUILoginView::WebUILoginView()
: profile_(NULL),
status_area_(NULL),
webui_login_(NULL),
keyboard_showing_(false),
focus_listener_added_(false),
keyboard_(NULL) {
}
void WebUILoginView::Init(const GURL& login_url) {
CHECK(!login_url.is_empty());
profile_ = ProfileManager::GetDefaultProfile();
webui_login_ = new DOMView();
AddChildView(webui_login_);
webui_login_->Init(profile_, NULL);
webui_login_->LoadURL(login_url);
webui_login_->SetVisible(true);
InitStatusArea();
registrar_.Add(this,
NotificationType::FOCUS_CHANGED_IN_PAGE,
NotificationService::AllSources());
registrar_.Add(this,
NotificationType::TAB_CONTENTS_DESTROYED,
NotificationService::AllSources());
}
// static
views::Widget* WebUILoginView::CreateWindowContainingView(
const gfx::Rect& bounds,
const GURL& login_url,
WebUILoginView** view) {
views::Widget* window = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = bounds;
window->Init(params);
*view = new WebUILoginView();
(*view)->Init(login_url);
window->SetContentsView(*view);
(*view)->UpdateWindowType();
return window;
}
std::string WebUILoginView::GetClassName() const {
return kViewClassName;
}
gfx::NativeWindow WebUILoginView::GetNativeWindow() const {
return GetWidget()->GetNativeWindow();
}
void WebUILoginView::FocusWillChange(views::View* focused_before,
views::View* focused_now) {
VirtualKeyboardType before = DecideKeyboardStateForView(focused_before);
VirtualKeyboardType now = DecideKeyboardStateForView(focused_now);
if (before != now) {
// TODO(varunjain): support other types of keyboard.
UpdateKeyboardAndLayout(now == GENERIC);
}
}
// WebUILoginView protected: ---------------------------------------------------
void WebUILoginView::Layout() {
const int kCornerPadding = 5;
gfx::Size status_area_size = status_area_->GetPreferredSize();
status_area_->SetBounds(
width() - status_area_size.width() - kCornerPadding,
kCornerPadding,
status_area_size.width(),
status_area_size.height());
if (webui_login_)
webui_login_->SetBoundsRect(bounds());
// TODO(rharrison): Hide touch specific code behind TOUCH_UI defines
if (!keyboard_)
return;
keyboard_->SetVisible(keyboard_showing_);
gfx::Rect keyboard_bounds = bounds();
keyboard_bounds.set_y(keyboard_bounds.height() - kKeyboardHeight);
keyboard_bounds.set_height(kKeyboardHeight);
keyboard_->SetBoundsRect(keyboard_bounds);
}
void WebUILoginView::ChildPreferredSizeChanged(View* child) {
Layout();
SchedulePaint();
}
Profile* WebUILoginView::GetProfile() const {
return NULL;
}
void WebUILoginView::ExecuteBrowserCommand(int id) const {
}
bool WebUILoginView::ShouldOpenButtonOptions(
const views::View* button_view) const {
if (button_view == status_area_->network_view())
return true;
if (button_view == status_area_->clock_view() ||
button_view == status_area_->input_method_view())
return false;
return true;
}
void WebUILoginView::OpenButtonOptions(const views::View* button_view) {
if (button_view == status_area_->network_view()) {
if (proxy_settings_dialog_.get() == NULL) {
proxy_settings_dialog_.reset(new ProxySettingsDialog(
this, GetNativeWindow()));
}
proxy_settings_dialog_->Show();
}
}
StatusAreaHost::ScreenMode WebUILoginView::GetScreenMode() const {
return kLoginMode;
}
StatusAreaHost::TextStyle WebUILoginView::GetTextStyle() const {
return kWhitePlain;
}
void WebUILoginView::OnDialogClosed() {
}
void WebUILoginView::OnLocaleChanged() {
// Proxy settings dialog contains localized strings.
proxy_settings_dialog_.reset();
SchedulePaint();
}
// WebUILoginView private: -----------------------------------------------------
void WebUILoginView::InitStatusArea() {
DCHECK(status_area_ == NULL);
status_area_ = new StatusAreaView(this);
status_area_->Init();
AddChildView(status_area_);
}
void WebUILoginView::UpdateWindowType() {
std::vector<int> params;
WmIpc::instance()->SetWindowType(
GTK_WIDGET(GetNativeWindow()),
WM_IPC_WINDOW_LOGIN_WEBUI,
&params);
}
void WebUILoginView::InitVirtualKeyboard() {
if (keyboard_)
return;
keyboard_ = new KeyboardContainerView(profile_, NULL);
keyboard_->SetVisible(false);
AddChildView(keyboard_);
}
void WebUILoginView::UpdateKeyboardAndLayout(bool should_show_keyboard) {
if (should_show_keyboard)
InitVirtualKeyboard();
if (should_show_keyboard == keyboard_showing_)
return;
DCHECK(keyboard_);
keyboard_showing_ = should_show_keyboard;
Layout();
}
WebUILoginView::VirtualKeyboardType
WebUILoginView::DecideKeyboardStateForView(views::View* view) {
if (!view)
return NONE;
std::string cname = view->GetClassName();
if (cname == views::Textfield::kViewClassName) {
return GENERIC;
} else if (cname == RenderWidgetHostViewViews::kViewClassName) {
TabContents* contents = webui_login_->tab_contents();
bool* editable = contents ? GetFocusedStateAccessor()->GetProperty(
contents->property_bag()) : NULL;
if (editable && *editable)
return GENERIC;
}
return NONE;
}
void WebUILoginView::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) {
// Only modify the keyboard state if the currently active tab sent the
// notification.
const TabContents* current_tab = webui_login_->tab_contents();
TabContents* source_tab = Source<TabContents>(source).ptr();
const bool editable = *Details<const bool>(details).ptr();
if (current_tab == source_tab && TabContentsHasFocus(source_tab))
UpdateKeyboardAndLayout(editable);
// Save the state of the focused field so that the keyboard visibility
// can be determined after tab switching.
GetFocusedStateAccessor()->SetProperty(
source_tab->property_bag(), editable);
} else if (type == NotificationType::TAB_CONTENTS_DESTROYED) {
GetFocusedStateAccessor()->DeleteProperty(
Source<TabContents>(source).ptr()->property_bag());
}
}
} // namespace chromeos
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_LOGIN_VIEW_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_LOGIN_VIEW_H_
#pragma once
#include "chrome/browser/chromeos/login/login_html_dialog.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
#include "views/focus/focus_manager.h"
#include "views/view.h"
class DOMView;
class GURL;
class KeyboardContainerView;
class NotificationDetails;
class NotificationSource;
class Profile;
namespace views {
class Widget;
class WindowDelegate;
}
namespace chromeos {
class StatusAreaView;
// View used to render a WebUI supporting Widget. This widget is used for the
// WebUI based start up and lock screens. It contains a StatusAreaView, DOMView,
// and on touch builds a KeyboardContainerView.
class WebUILoginView : public views::View,
public StatusAreaHost,
public chromeos::LoginHtmlDialog::Delegate,
public views::FocusChangeListener,
public NotificationObserver {
public:
enum VirtualKeyboardType {
NONE,
GENERIC,
URL,
};
// Internal class name.
static const char kViewClassName[];
WebUILoginView();
// Initializes the webui login view. |login_url| must be specified.
void Init(const GURL& login_url);
// Creates a window containing an instance of WebUILoginView as the root
// view. The caller is responsible for showing (and closing) the returned
// widget. The WebUILoginView is set in |view|. |login_url| is the webpage
// that will be opened in the DOMView.
static views::Widget* CreateWindowContainingView(
const gfx::Rect& bounds,
const GURL& login_url,
WebUILoginView** view);
// Overriden from views::Views:
virtual std::string GetClassName() const OVERRIDE;
// Overridden from StatusAreaHost:
virtual gfx::NativeWindow GetNativeWindow() const;
// Overridden from views::FocusChangeListener:
virtual void FocusWillChange(views::View* focused_before,
views::View* focused_now);
protected:
// Overridden from views::View:
virtual void Layout() OVERRIDE;
virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
// Overridden from StatusAreaHost:
virtual Profile* GetProfile() const OVERRIDE;
virtual void ExecuteBrowserCommand(int id) const OVERRIDE;
virtual bool ShouldOpenButtonOptions(
const views::View* button_view) const OVERRIDE;
virtual void OpenButtonOptions(const views::View* button_view) OVERRIDE;
virtual ScreenMode GetScreenMode() const OVERRIDE;
virtual TextStyle GetTextStyle() const OVERRIDE;
// Overridden from LoginHtmlDialog::Delegate:
virtual void OnDialogClosed() OVERRIDE;
virtual void OnLocaleChanged() OVERRIDE;
private:
// Creates and adds the status_area.
void InitStatusArea();
// Invokes SetWindowType for the window. This is invoked during startup and
// after we've painted.
void UpdateWindowType();
void InitVirtualKeyboard();
void UpdateKeyboardAndLayout(bool should_show_keyboard);
VirtualKeyboardType DecideKeyboardStateForView(views::View* view);
// Overridden from NotificationObserver.
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) OVERRIDE;
Profile* profile_;
StatusAreaView* status_area_;
// DOMView for rendering a webpage as a webui login.
DOMView* webui_login_;
// Proxy settings dialog that can be invoked from network menu.
scoped_ptr<LoginHtmlDialog> proxy_settings_dialog_;
bool keyboard_showing_;
bool focus_listener_added_;
KeyboardContainerView* keyboard_;
NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(WebUILoginView);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_LOGIN_VIEW_H_
......@@ -23,6 +23,7 @@
#if defined(OS_CHROMEOS) && defined(TOUCH_UI)
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/input_method_library.h"
#include "chrome/browser/chromeos/login/dom_login_display.h"
#endif
namespace {
......@@ -64,6 +65,12 @@ void InputFunction::Run() {
}
views::Widget* SendKeyboardEventInputFunction::GetTopLevelWidget() {
#if defined(OS_CHROMEOS) && defined(TOUCH_UI)
views::Widget* login_window = chromeos::DOMLoginDisplay::GetLoginWindow();
if (login_window)
return login_window;
#endif
Browser* browser = GetCurrentBrowser();
if (!browser)
return NULL;
......
......@@ -427,12 +427,6 @@
'browser/chromeos/frame/bubble_frame_view.h',
'browser/chromeos/frame/bubble_window.cc',
'browser/chromeos/frame/bubble_window.h',
'browser/chromeos/frame/dom_browser.cc',
'browser/chromeos/frame/dom_browser.h',
'browser/chromeos/frame/dom_browser_view.cc',
'browser/chromeos/frame/dom_browser_view.h',
'browser/chromeos/frame/dom_browser_view_layout.cc',
'browser/chromeos/frame/dom_browser_view_layout.h',
'browser/chromeos/frame/panel_browser_view.cc',
'browser/chromeos/frame/panel_browser_view.h',
'browser/chromeos/frame/panel_controller.cc',
......@@ -612,6 +606,8 @@
'browser/chromeos/login/web_page_screen.h',
'browser/chromeos/login/web_page_view.cc',
'browser/chromeos/login/web_page_view.h',
'browser/chromeos/login/webui_login_view.h',
'browser/chromeos/login/webui_login_view.cc',
'browser/chromeos/login/wizard_accessibility_handler.cc',
'browser/chromeos/login/wizard_accessibility_handler.h',
'browser/chromeos/login/wizard_accessibility_helper.cc',
......@@ -3599,6 +3595,7 @@
'sources/': [
['exclude', '^browser/chromeos/frame/dom_*'],
['exclude', '^browser/chromeos/login/dom_*'],
['exclude', '^browser/chromeos/login/webui_*'],
['exclude', '^browser/extensions/extension_input_ui_api.cc'],
['exclude', '^browser/extensions/extension_input_ui_api.h'],
['exclude', '^browser/renderer_host/render_widget_host_view_views.*'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment