Move thumbar_host_ from TreeHost to NativeWindow

This commit is contained in:
Cheng Zhao 2015-08-06 10:25:50 +08:00
parent d175a68586
commit 39af10cc8d
4 changed files with 32 additions and 43 deletions

View file

@ -46,6 +46,7 @@
#elif defined(OS_WIN) #elif defined(OS_WIN)
#include "atom/browser/ui/views/win_frame_view.h" #include "atom/browser/ui/views/win_frame_view.h"
#include "atom/browser/ui/win/atom_desktop_window_tree_host_win.h" #include "atom/browser/ui/win/atom_desktop_window_tree_host_win.h"
#include "atom/browser/ui/win/thumbar_host.h"
#include "base/win/scoped_comptr.h" #include "base/win/scoped_comptr.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "ui/base/win/shell.h" #include "ui/base/win/shell.h"
@ -720,13 +721,12 @@ bool NativeWindowViews::IsVisibleOnAllWorkspaces() {
bool NativeWindowViews::SetThumbarButtons( bool NativeWindowViews::SetThumbarButtons(
const std::vector<NativeWindow::ThumbarButton>& buttons) { const std::vector<NativeWindow::ThumbarButton>& buttons) {
#if defined(OS_WIN) #if defined(OS_WIN)
if (atom_desktop_window_tree_host_win_) { if (!thumbar_host_)
return atom_desktop_window_tree_host_win_->SetThumbarButtons( thumbar_host_.reset(new ThumbarHost(GetAcceleratedWidget()));
views::HWNDForNativeWindow(window_->GetNativeWindow()), return thumbar_host_->SetThumbarButtons(buttons);
buttons); #else
}
#endif
return false; return false;
#endif
} }
gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() { gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
@ -890,6 +890,18 @@ void NativeWindowViews::GetDevToolsWindowWMClass(
} }
#endif #endif
#if defined(OS_WIN)
bool NativeWindowViews::PreHandleMSG(
UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) {
// Handle thumbar button click message.
if (message == WM_COMMAND && HIWORD(w_param) == THBN_CLICKED &&
thumbar_host_)
return thumbar_host_->HandleThumbarButtonEvent(LOWORD(w_param));
else
return false;
}
#endif
void NativeWindowViews::HandleKeyboardEvent( void NativeWindowViews::HandleKeyboardEvent(
content::WebContents*, content::WebContents*,
const content::NativeWebKeyboardEvent& event) { const content::NativeWebKeyboardEvent& event) {

View file

@ -27,8 +27,10 @@ namespace atom {
class GlobalMenuBarX11; class GlobalMenuBarX11;
class MenuBar; class MenuBar;
class WindowStateWatcher; class WindowStateWatcher;
#if defined(OS_WIN) #if defined(OS_WIN)
class AtomDesktopWindowTreeHostWin; class AtomDesktopWindowTreeHostWin;
class ThumbarHost;
#endif #endif
class NativeWindowViews : public NativeWindow, class NativeWindowViews : public NativeWindow,
@ -134,6 +136,12 @@ class NativeWindowViews : public NativeWindow,
std::string* name, std::string* class_name) override; std::string* name, std::string* class_name) override;
#endif #endif
#if defined(OS_WIN)
// MessageHandlerDelegate:
bool PreHandleMSG(
UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) override;
#endif
// NativeWindow: // NativeWindow:
void HandleKeyboardEvent( void HandleKeyboardEvent(
content::WebContents*, content::WebContents*,
@ -171,6 +179,8 @@ class NativeWindowViews : public NativeWindow,
// Records window was whether restored from minimized state or maximized // Records window was whether restored from minimized state or maximized
// state. // state.
bool is_minimized_; bool is_minimized_;
// In charge of running thumbar related APIs.
scoped_ptr<ThumbarHost> thumbar_host_;
#endif #endif
// Handles unhandled keyboard messages coming back from the renderer process. // Handles unhandled keyboard messages coming back from the renderer process.

View file

@ -4,10 +4,7 @@
#include "atom/browser/ui/win/atom_desktop_window_tree_host_win.h" #include "atom/browser/ui/win/atom_desktop_window_tree_host_win.h"
#include <shobjidl.h> #include "atom/browser/ui/win/message_handler_delegate.h"
#include "atom/browser/native_window.h"
#include "atom/browser/ui/win/thumbar_host.h"
namespace atom { namespace atom {
@ -23,31 +20,9 @@ AtomDesktopWindowTreeHostWin::AtomDesktopWindowTreeHostWin(
AtomDesktopWindowTreeHostWin::~AtomDesktopWindowTreeHostWin() { AtomDesktopWindowTreeHostWin::~AtomDesktopWindowTreeHostWin() {
} }
bool AtomDesktopWindowTreeHostWin::SetThumbarButtons( bool AtomDesktopWindowTreeHostWin::PreHandleMSG(
HWND window, UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) {
const std::vector<NativeWindow::ThumbarButton>& buttons) { return delegate_->PreHandleMSG(message, w_param, l_param, result);
if (!thumbar_host_.get()) {
thumbar_host_.reset(new ThumbarHost(window));
}
return thumbar_host_->SetThumbarButtons(buttons);
}
bool AtomDesktopWindowTreeHostWin::PreHandleMSG(UINT message,
WPARAM w_param,
LPARAM l_param,
LRESULT* result) {
switch (message) {
case WM_COMMAND: {
// Handle thumbar button click message.
int id = LOWORD(w_param);
int thbn_message = HIWORD(w_param);
if (thbn_message == THBN_CLICKED && thumbar_host_ &&
thumbar_host_->HandleThumbarButtonEvent(id))
return true;
}
}
return false;
} }
} // namespace atom } // namespace atom

View file

@ -10,8 +10,6 @@
#include <vector> #include <vector>
#include "atom/browser/native_window.h" #include "atom/browser/native_window.h"
#include "atom/browser/ui/win/thumbar_host.h"
#include "base/memory/scoped_ptr.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
namespace atom { namespace atom {
@ -26,10 +24,6 @@ class AtomDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin {
views::DesktopNativeWidgetAura* desktop_native_widget_aura); views::DesktopNativeWidgetAura* desktop_native_widget_aura);
~AtomDesktopWindowTreeHostWin() override; ~AtomDesktopWindowTreeHostWin() override;
bool SetThumbarButtons(
HWND window,
const std::vector<NativeWindow::ThumbarButton>& buttons);
protected: protected:
bool PreHandleMSG( bool PreHandleMSG(
UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) override; UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) override;
@ -37,8 +31,6 @@ class AtomDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin {
private: private:
MessageHandlerDelegate* delegate_; // weak ref MessageHandlerDelegate* delegate_; // weak ref
scoped_ptr<ThumbarHost> thumbar_host_;
DISALLOW_COPY_AND_ASSIGN(AtomDesktopWindowTreeHostWin); DISALLOW_COPY_AND_ASSIGN(AtomDesktopWindowTreeHostWin);
}; };