Home | History | Annotate | Download | only in views
      1 // Copyright (c) 2011 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 // DOMView is a ChromeView that displays the content of a web DOM.
      6 // It should be used with data: URLs.
      7 
      8 #ifndef CHROME_BROWSER_UI_VIEWS_DOM_VIEW_H_
      9 #define CHROME_BROWSER_UI_VIEWS_DOM_VIEW_H_
     10 #pragma once
     11 
     12 #include "base/memory/scoped_ptr.h"
     13 #include "googleurl/src/gurl.h"
     14 #include "views/controls/native/native_view_host.h"
     15 #include "views/events/event.h"
     16 
     17 class Profile;
     18 class SiteInstance;
     19 class TabContents;
     20 
     21 class DOMView : public views::NativeViewHost {
     22  public:
     23   DOMView();
     24   virtual ~DOMView();
     25 
     26   // Initialize the view, creating the contents. This should be
     27   // called once the view has been added to a container.
     28   //
     29   // If |instance| is not null, then the view will be loaded in the same
     30   // process as the given instance.
     31   bool Init(Profile* profile, SiteInstance* instance);
     32 
     33   // Loads the given URL into the page. You must have previously called Init().
     34   void LoadURL(const GURL& url);
     35 
     36   // The tab contents displaying the actual contents.
     37   TabContents* tab_contents() const { return tab_contents_.get(); }
     38 
     39  protected:
     40   // Overridden from View.
     41   virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e) OVERRIDE;
     42   virtual void OnFocus() OVERRIDE;
     43   virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
     44                                     views::View* child) OVERRIDE;
     45 
     46   // AttachTabContents calls Attach to hook up the NativeViewHost. This is
     47   // here because depending on whether this is a touch build or not the
     48   // implementation varies slightly, while Detach is the same in both cases.
     49   void AttachTabContents();
     50 
     51   // Returns new allocated TabContents instance, caller is responsible deleting.
     52   // Override in derived classes to replace TabContents with derivative.
     53   virtual TabContents* CreateTabContents(Profile* profile,
     54                                          SiteInstance* instance);
     55 
     56   scoped_ptr<TabContents> tab_contents_;
     57 
     58  private:
     59   bool initialized_;
     60 
     61   DISALLOW_COPY_AND_ASSIGN(DOMView);
     62 };
     63 
     64 #endif  // CHROME_BROWSER_UI_VIEWS_DOM_VIEW_H_
     65