bool DesktopWindowManager::HandleMouseEvent(
            view::Widget* widget, const view::MouseEvent& event)
        {
            if(mouse_capture_)
            {
                view::MouseEvent translated(event, widget->GetRootView(),
                    mouse_capture_->GetRootView());
                mouse_capture_->OnMouseEvent(translated);
                return true;
            }

            if(event.type() == ui::ET_MOUSE_PRESSED)
            {
                ActivateWidgetAtLocation(widget, event.location());
            }
            else if(event.type()==ui::ET_MOUSEWHEEL && active_widget_)
            {
                return active_widget_->OnMouseEvent(event);
            }

            if(window_controller_.get())
            {
                if(!window_controller_->OnMouseEvent(event))
                {
                    ReleaseMouseCapture();
                    window_controller_.reset();
                }
                return true;
            }

            return false;
        }
void BaseTabStrip::MaybeStartDrag(BaseTab* tab,
                                  const view::MouseEvent& event)
{
    // Don't accidentally start any drag operations during animations if the
    // mouse is down... during an animation tabs are being resized automatically,
    // so the View system can misinterpret this easily if the mouse is down that
    // the user is dragging.
    if(IsAnimating() || tab->closing() ||
        controller_->HasAvailableDragActions()==0)
    {
        return;
    }
    int model_index = GetModelIndexOfBaseTab(tab);
    if(!IsValidModelIndex(model_index))
    {
        CHECK(false);
        return;
    }
    drag_controller_.reset(new DraggedTabController());
    std::vector<BaseTab*> tabs;
    int size_to_selected = 0;
    int x = tab->GetMirroredXInView(event.x());
    int y = event.y();
    // Build the set of selected tabs to drag and calculate the offset from the
    // first selected tab.
    for(int i=0; i<tab_count(); ++i)
    {
        BaseTab* other_tab = base_tab_at_tab_index(i);
        if(IsTabSelected(other_tab) && !other_tab->closing())
        {
            tabs.push_back(other_tab);
            if(other_tab == tab)
            {
                size_to_selected = GetSizeNeededForTabs(tabs);
                if(type() == HORIZONTAL_TAB_STRIP)
                {
                    x = size_to_selected - tab->width() + x;
                }
                else
                {
                    y = size_to_selected - tab->height() + y;
                }
            }
        }
    }
    DCHECK(!tabs.empty());
    DCHECK(std::find(tabs.begin(), tabs.end(), tab) != tabs.end());
    drag_controller_->Init(this, tab, tabs, gfx::Point(x, y),
        tab->GetMirroredXInView(event.x()));
}
Beispiel #3
0
bool BaseTab::OnMousePressed(const view::MouseEvent& event)
{
    if(!controller())
    {
        return false;
    }

    if(event.IsOnlyLeftMouseButton())
    {
        if(event.IsShiftDown() && event.IsControlDown())
        {
            controller()->AddSelectionFromAnchorTo(this);
        }
        else if(event.IsShiftDown())
        {
            controller()->ExtendSelectionTo(this);
        }
        else if(event.IsControlDown())
        {
            controller()->ToggleSelected(this);
            if(!IsSelected())
            {
                // Don't allow dragging non-selected tabs.
                return false;
            }
        }
        else if(!IsSelected())
        {
            controller()->SelectTab(this);
        }
        else if(IsActive())
        {
            controller()->ClickActiveTab(this);
        }
        controller()->MaybeStartDrag(this, event);
    }
    return true;
}
Beispiel #4
0
void BaseTab::OnMouseReleased(const view::MouseEvent& event)
{
    if(!controller())
    {
        return;
    }

    // Notify the drag helper that we're done with any potential drag operations.
    // Clean up the drag helper, which is re-created on the next mouse press.
    // In some cases, ending the drag will schedule the tab for destruction; if
    // so, bail immediately, since our members are already dead and we shouldn't
    // do anything else except drop the tab where it is.
    if(controller()->EndDrag(false))
    {
        return;
    }

    // Close tab on middle click, but only if the button is released over the tab
    // (normal windows behavior is to discard presses of a UI element where the
    // releases happen off the element).
    if(event.IsMiddleMouseButton())
    {
        if(HitTest(event.location()))
        {
            controller()->CloseTab(this);
        }
        else if(closing_)
        {
            // We're animating closed and a middle mouse button was pushed on us but
            // we don't contain the mouse anymore. We assume the user is clicking
            // quicker than the animation and we should close the tab that falls under
            // the mouse.
            BaseTab* closest_tab = controller()->GetTabAt(this, event.location());
            if(closest_tab)
            {
                controller()->CloseTab(closest_tab);
            }
        }
    }
    else if(event.IsOnlyLeftMouseButton() && !event.IsShiftDown() &&
        !event.IsControlDown())
    {
        // If the tab was already selected mouse pressed doesn't change the
        // selection. Reset it now to handle the case where multiple tabs were
        // selected.
        controller()->SelectTab(this);
    }
}